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

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

Defined Under Namespace

Classes: Matcher

Instance Method Summary collapse

Constructor Details

#initialize(options, &block) ⇒ MenuBuilder



9
10
11
12
13
14
# File 'lib/adhearsion/call_controller/input/menu_builder.rb', line 9

def initialize(options, &block)
  @options = options
  @matchers = []
  @callbacks = {}
  build(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)



79
80
81
82
83
84
85
# File 'lib/adhearsion/call_controller/input/menu_builder.rb', line 79

def method_missing(method_name, *args, &block)
  if @context
    @context.send method_name, *args, &block
  else
    super
  end
end

Instance Method Details

#execute(output_document, controller) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/adhearsion/call_controller/input/menu_builder.rb', line 34

def execute(output_document, controller)
  catch :match do
    (@options[:tries] || 1).times do
      result = PromptBuilder.new(output_document, grammars, @options).execute(controller)
      process_result result
    end
    execute_hook :failure
  end
end

#failure(&block) ⇒ Object



30
31
32
# File 'lib/adhearsion/call_controller/input/menu_builder.rb', line 30

def failure(&block)
  register_user_supplied_callback :failure, &block
end

#invalid(&block) ⇒ Object



22
23
24
# File 'lib/adhearsion/call_controller/input/menu_builder.rb', line 22

def invalid(&block)
  register_user_supplied_callback :nomatch, &block
end

#match(*args, &block) ⇒ Object



16
17
18
19
20
# File 'lib/adhearsion/call_controller/input/menu_builder.rb', line 16

def match(*args, &block)
  payload = block || args.pop

  @matchers << Matcher.new(payload, args)
end

#timeout(&block) ⇒ Object



26
27
28
# File 'lib/adhearsion/call_controller/input/menu_builder.rb', line 26

def timeout(&block)
  register_user_supplied_callback :noinput, &block
end