Class: AdhearsionASR::MenuBuilder::Matcher

Inherits:
Struct
  • Object
show all
Defined in:
lib/adhearsion-asr/menu_builder.rb

Instance Method Summary collapse

Instance Method Details

#apply_to_grammar(grammar) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/adhearsion-asr/menu_builder.rb', line 112

def apply_to_grammar(grammar)
  possible_options = calculate_possible_options
  if possible_options.count > 1
    grammar.one_of do
      possible_options.each do |key|
        item { key.to_s }
      end
    end
  else
    keys.first.to_s
  end
end

#calculate_possible_optionsObject



125
126
127
# File 'lib/adhearsion-asr/menu_builder.rb', line 125

def calculate_possible_options
  keys.map { |key| key.respond_to?(:to_a) ? key.to_a : key }.flatten
end

#dispatch(controller, utterance) ⇒ Object



104
105
106
107
108
109
110
# File 'lib/adhearsion-asr/menu_builder.rb', line 104

def dispatch(controller, utterance)
  if payload.is_a?(Proc)
    controller.instance_exec utterance, &payload
  else
    controller.invoke payload, extension: utterance
  end
end