Class: Adhearsion::CallController::Input::MenuBuilder::Matcher

Inherits:
Struct
  • Object
show all
Defined in:
lib/adhearsion/call_controller/input/menu_builder.rb

Instance Method Summary collapse

Instance Method Details

#apply_to_grammar(grammar) ⇒ Object


116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/adhearsion/call_controller/input/menu_builder.rb', line 116

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


129
130
131
# File 'lib/adhearsion/call_controller/input/menu_builder.rb', line 129

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

#dispatch(controller, utterance) ⇒ Object


108
109
110
111
112
113
114
# File 'lib/adhearsion/call_controller/input/menu_builder.rb', line 108

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