module Punchblock::Translator::InputComponent

Public Instance Methods

execute() click to toggle source
# File lib/punchblock/translator/input_component.rb, line 6
def execute
  validate
  setup_dtmf_recognizer
  send_ref
  start_timers
rescue OptionError, ArgumentError => e
  with_error 'option error', e.message
end
execute_command(command) click to toggle source
Calls superclass method
# File lib/punchblock/translator/input_component.rb, line 21
def execute_command(command)
  case command
  when Punchblock::Component::Stop
    command.response = true
    complete Punchblock::Event::Complete::Stop.new
  else
    super
  end
end
match(match) click to toggle source
# File lib/punchblock/translator/input_component.rb, line 31
def match(match)
  complete success_reason(match)
end
noinput() click to toggle source
# File lib/punchblock/translator/input_component.rb, line 39
def noinput
  complete Punchblock::Component::Input::Complete::NoInput.new
end
nomatch() click to toggle source
# File lib/punchblock/translator/input_component.rb, line 35
def nomatch
  complete Punchblock::Component::Input::Complete::NoMatch.new
end
process_dtmf(digit) click to toggle source
# File lib/punchblock/translator/input_component.rb, line 15
def process_dtmf(digit)
  @recognizer << digit
rescue Celluloid::DeadActorError
  pb_logger.warn 'DTMF digit received into a dead recognizer. Dropping digit.'
end

Private Instance Methods

complete(reason) click to toggle source
# File lib/punchblock/translator/input_component.rb, line 77
def complete(reason)
  unregister_dtmf_event_handler
  send_complete_event reason
end
input_node() click to toggle source
# File lib/punchblock/translator/input_component.rb, line 45
def input_node
  @component_node
end
setup_dtmf_recognizer() click to toggle source
# File lib/punchblock/translator/input_component.rb, line 55
def setup_dtmf_recognizer
  @recognizer = DTMFRecognizer.new self,
                  input_node.grammars.first,
                  (input_node.initial_timeout || -1),
                  (input_node.inter_digit_timeout || -1),
                  input_node.terminator
end
start_timers() click to toggle source
# File lib/punchblock/translator/input_component.rb, line 63
def start_timers
  @recognizer.start_timers
end
success_reason(match) click to toggle source
# File lib/punchblock/translator/input_component.rb, line 67
def success_reason(match)
  nlsml = RubySpeech::NLSML.draw do
    interpretation confidence: match.confidence do
      instance match.interpretation
      input match.utterance, mode: match.mode
    end
  end
  Punchblock::Component::Input::Complete::Match.new :nlsml => nlsml
end
validate() click to toggle source
# File lib/punchblock/translator/input_component.rb, line 49
def validate
  raise OptionError, 'A grammar document is required.' unless input_node.grammars.first
  raise OptionError, 'Only a single grammar is supported.' unless input_node.grammars.size == 1
  raise OptionError, 'A mode value other than DTMF is unsupported.' unless input_node.mode == :dtmf
end