Sha256: 984aae64d5ae278eb6cd06dc02328240ec280a5579634eac0db443a1ea11a95f

Contents?: true

Size: 1.69 KB

Versions: 5

Compression:

Stored size: 1.69 KB

Contents

# encoding: utf-8

module Punchblock
  module Translator
    module InputComponent
      def execute
        validate

        @recognizer = DTMFRecognizer.new self,
                                         @component_node.grammar.value,
                                         (@component_node.initial_timeout || -1),
                                         (@component_node.inter_digit_timeout || -1)

        send_ref

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

      def process_dtmf(digit)
        @recognizer << digit
      end

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

      def match(mode, confidence, utterance, interpretation)
        complete Punchblock::Component::Input::Complete::Success.new(:mode => mode, :confidence => confidence, :utterance => utterance, :interpretation => interpretation)
      end

      def nomatch
        complete Punchblock::Component::Input::Complete::NoMatch.new
      end

      def noinput
        complete Punchblock::Component::Input::Complete::NoInput.new
      end

      private

      def validate
        raise OptionError, 'A grammar document is required.' unless @component_node.grammar
        raise OptionError, 'A mode value other than DTMF is unsupported.' unless @component_node.mode == :dtmf
      end

      def complete(reason)
        unregister_dtmf_event_handler
        @recognizer.finalize if @recognizer
        send_complete_event reason
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
punchblock-1.9.4 lib/punchblock/translator/input_component.rb
punchblock-1.9.3 lib/punchblock/translator/input_component.rb
punchblock-1.9.2 lib/punchblock/translator/input_component.rb
punchblock-1.9.1 lib/punchblock/translator/input_component.rb
punchblock-1.9.0 lib/punchblock/translator/input_component.rb