Permalink
Browse files

Merge pull request #31 from hermes-logicalbricks/master

Now work in Linux with mpg123 too
  • Loading branch information...
2 parents e6c6e6d + 68808a9 commit 95cdc245804f1cea650bfe83ecef6268e7f029fc @mattsears committed Oct 6, 2012
Showing with 17 additions and 3 deletions.
  1. +1 −1 README.md
  2. +15 −2 lib/nyan_cat_music_formatter.rb
  3. +1 −0 spec/nyan_cat_music_formatter_spec.rb
View
@@ -73,7 +73,7 @@ Make sure your .rspec file in your application's root directory contains the fol
Then run `rspec spec` and enjoy Nyan Cat formatted text output accompanied by the Nyan Cat song by default!
-**This currently only works on Mac OS X or on Linux (if you have mpg321 installed).**
+**This currently only works on Mac OS X or on Linux (if you have mpg321 or mpg123 installed).**
Contributing
----------
@@ -33,13 +33,26 @@ def nyan_mp3
def start input
super
kernel.system("afplay #{nyan_mp3} &") if osx?
- kernel.system("[ -e #{nyan_mp3} ] && type mpg321 &>/dev/null && mpg321 #{nyan_mp3} &>/dev/null &") if linux?
+ play_on_linux if linux?
end
def kill_music
if File.exists? nyan_mp3
system("killall -9 afplay &>/dev/null") if osx?
- system("killall -9 mpg321 &>/dev/null") if linux?
+ kill_music_on_linux if linux?
end
end
+
+ private
+
+ def play_on_linux
+ kernel.system("[ -e #{nyan_mp3} ] && type mpg321 &>/dev/null && mpg321 #{nyan_mp3} &>/dev/null &") if kernel.system('which mpg321 &>/dev/null && type mpg321 &>/dev/null')
+ kernel.system("[ -e #{nyan_mp3} ] && type mpg123 &>/dev/null && mpg123 #{nyan_mp3} &>/dev/null &") if kernel.system('which mpg123 &>/dev/null && type mpg123 &>/dev/null')
+ end
+
+ def kill_music_on_linux
+ system("killall -9 mpg321 &>/dev/null") if kernel.system("which mpg321 &>/dev/null && type mpg321 &>/dev/null")
+ system("killall -9 mpg123 &>/dev/null") if kernel.system("which mpg123 &>/dev/null && type mpg123 &>/dev/null")
+ end
+
end
@@ -69,6 +69,7 @@ def seen
it 'plays the song for linux too' do
formatter.start 10
mock_kernel.seen.any? { |entry| entry. end_with? "mpg321 #{path_to_mp3} &>/dev/null &" }.should be
+ mock_kernel.seen.any? { |entry| entry. end_with? "mpg123 #{path_to_mp3} &>/dev/null &" }.should be
end
end

0 comments on commit 95cdc24

Please sign in to comment.