Class: Mpg321::ProcessWrapper

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

Instance Method Summary collapse

Constructor Details

#initializeProcessWrapper

Returns a new instance of ProcessWrapper.



5
6
7
8
9
10
# File 'lib/mpg321/process_wrapper.rb', line 5

def initialize
  spawn_mpg321

  @callbacks = Hash.new { |h, e| h[e] = Array.new }
  @read_thr  = async_handle_stdoe
end

Instance Method Details

#on(event, &block) ⇒ Object



16
17
18
# File 'lib/mpg321/process_wrapper.rb', line 16

def on(event, &block)
  @callbacks[event] << block
end

#quitObject



20
21
22
23
24
# File 'lib/mpg321/process_wrapper.rb', line 20

def quit
  send_command 'Q'
  @read_thr.join
  @wait_thr.value
end

#send_command(command, *args) ⇒ Object



12
13
14
# File 'lib/mpg321/process_wrapper.rb', line 12

def send_command command, *args
  @stdin.puts [command, *(args.map(&:to_s))].join(' ')
end