Class: Airhorn

Inherits:
Object
  • Object
show all
Defined in:
lib/airhorn.rb

Class Method Summary collapse

Class Method Details

.audio_file_path(file) ⇒ Object



21
22
23
# File 'lib/airhorn.rb', line 21

def self.audio_file_path (file)
  File.expand_path("../../audio/#{file}", __FILE__)
end

.blow(args) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/airhorn.rb', line 2

def self.blow (args)
  pid = play audio_file_path('airhorn.wav')
  return if pid.nil?
  tpid = spawn('printf "B"; while sleep 0.1; do printf "R"; done')
  Process.wait pid
  Process.kill 'TERM', tpid
  return
end

.play(file_path) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/airhorn.rb', line 11

def self.play (file_path)
  if system 'command -v afplay >/dev/null 2>&1'
    # mac
    spawn("afplay -t 1.4 #{file_path} >/dev/null 2>&1")
  elsif system 'command -v aplay >/dev/null 2>&1'
    # linux
    spawn("aplay -d 1.4 #{file_path} >/dev/null 2>&1")
  end
end