Class: AdhearsionASR::MenuBuilder

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

Defined Under Namespace

Classes: Matcher

Instance Method Summary collapse

Constructor Details

#initialize(options, &block) ⇒ MenuBuilder

Returns a new instance of MenuBuilder.



5
6
7
8
9
10
# File 'lib/adhearsion-asr/menu_builder.rb', line 5

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)



75
76
77
78
79
80
81
# File 'lib/adhearsion-asr/menu_builder.rb', line 75

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



30
31
32
33
34
35
36
37
38
# File 'lib/adhearsion-asr/menu_builder.rb', line 30

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



26
27
28
# File 'lib/adhearsion-asr/menu_builder.rb', line 26

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

#invalid(&block) ⇒ Object



18
19
20
# File 'lib/adhearsion-asr/menu_builder.rb', line 18

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

#match(*args, &block) ⇒ Object



12
13
14
15
16
# File 'lib/adhearsion-asr/menu_builder.rb', line 12

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

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

#timeout(&block) ⇒ Object



22
23
24
# File 'lib/adhearsion-asr/menu_builder.rb', line 22

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