Module: Punchblock::Translator::InputComponent

Included in:
Asterisk::Component::Input, Freeswitch::Component::Input
Defined in:
lib/punchblock/translator/input_component.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/punchblock/translator/input_component.rb', line 12

def execute
  validate
  send_ref

  @grammar = prepare_grammar

  begin_initial_timer @initial_timeout/1000 unless @initial_timeout == -1

  @dtmf_handler_id = register_dtmf_event_handler
rescue OptionError => e
  with_error 'option error', e.message
end

#execute_command(command) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/punchblock/translator/input_component.rb', line 38

def execute_command(command)
  case command
  when Punchblock::Component::Stop
    command.response = true
    complete Punchblock::Event::Complete::Stop.new
  else
    super
  end
end

#process_dtmf(digit) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/punchblock/translator/input_component.rb', line 25

def process_dtmf(digit)
  @buffer << digit
  cancel_initial_timer
  case (match = @grammar.match @buffer.dup)
  when RubySpeech::GRXML::Match
    complete success_reason(match)
  when RubySpeech::GRXML::NoMatch
    complete Punchblock::Component::Input::Complete::NoMatch.new
  when RubySpeech::GRXML::PotentialMatch
    reset_inter_digit_timer
  end
end

#setupObject



6
7
8
9
10
# File 'lib/punchblock/translator/input_component.rb', line 6

def setup
  @buffer = ""
  @initial_timeout = @component_node.initial_timeout || -1
  @inter_digit_timeout = @component_node.inter_digit_timeout || -1
end