Class: NyanCatMusicFormatter
Constant Summary
collapse
- MUSIC_LENGTH =
27.06
Instance Method Summary
collapse
Instance Method Details
#kernel ⇒ Object
20
21
22
|
# File 'lib/nyan_cat_music_formatter.rb', line 20
def kernel
@kernel ||= Kernel
end
|
#kernel=(kernel) ⇒ Object
16
17
18
|
# File 'lib/nyan_cat_music_formatter.rb', line 16
def kernel=(kernel)
@kernel = kernel
end
|
#kill_music ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/nyan_cat_music_formatter.rb', line 54
def kill_music
if File.exists? nyan_mp3
if osx?
system("killall -9 afplay &>/dev/null")
elsif linux?
kill_music_on_linux
end
end
end
|
#linux? ⇒ Boolean
12
13
14
|
# File 'lib/nyan_cat_music_formatter.rb', line 12
def linux?
platform.downcase.include?('linux')
end
|
#nyan_mp3 ⇒ Object
32
33
34
|
# File 'lib/nyan_cat_music_formatter.rb', line 32
def nyan_mp3
File.expand_path('../../data/nyan-cat.mp3', __FILE__)
end
|
#osx? ⇒ Boolean
TODO make it work with variable length songs
8
9
10
|
# File 'lib/nyan_cat_music_formatter.rb', line 8
def osx?
platform.downcase.include?("darwin")
end
|
28
29
30
|
# File 'lib/nyan_cat_music_formatter.rb', line 28
def platform
@platform ||= RUBY_PLATFORM
end
|
24
25
26
|
# File 'lib/nyan_cat_music_formatter.rb', line 24
def platform=(platform)
@platform = platform
end
|
#start(input) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/nyan_cat_music_formatter.rb', line 36
def start input
super
t = Thread.new do
loop do
if osx?
kernel.system("afplay #{nyan_mp3} &")
elsif linux?
play_on_linux
end
Thread.current["started_playing"] ||= true
sleep MUSIC_LENGTH
end
end
until t["started_playing"]
sleep 0.001
end
end
|