Class: Adhearsion::VoIP::MenuBuilder
- Inherits:
-
Object
- Object
- Adhearsion::VoIP::MenuBuilder
show all
- Defined in:
- lib/adhearsion/voip/menu_state_machine/menu_builder.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of MenuBuilder.
7
8
9
10
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 7
def initialize
@patterns = []
@menu_callbacks = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(match_payload, *patterns, &block) ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 12
def method_missing(match_payload, *patterns, &block)
if patterns.any?
patterns.each do |pattern|
@patterns << MatchCalculator.build_with_pattern(pattern, match_payload)
end
else
raise ArgumentError, "You cannot call this method without patterns!"
end
nil
end
|
Instance Method Details
#calculate_matches_for(result) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 47
def calculate_matches_for(result)
CalculatedMatchCollection.new.tap do |collection|
weighted_match_calculators.each do |pattern|
collection << pattern.match(result)
end
end
end
|
#execute_hook_for(symbol, input) ⇒ Object
27
28
29
30
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 27
def execute_hook_for(symbol, input)
callback = @menu_callbacks[symbol]
callback.call input if callback
end
|
#on_failure(&block) ⇒ Object
42
43
44
45
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 42
def on_failure(&block)
raise LocalJumpError, "Must supply a block!" unless block_given?
@menu_callbacks[:failure] = block
end
|
#on_invalid(&block) ⇒ Object
32
33
34
35
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 32
def on_invalid(&block)
raise LocalJumpError, "Must supply a block!" unless block_given?
@menu_callbacks[:invalid] = block
end
|
#on_premature_timeout(&block) ⇒ Object
37
38
39
40
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 37
def on_premature_timeout(&block)
raise LocalJumpError, "Must supply a block!" unless block_given?
@menu_callbacks[:premature_timeout] = block
end
|
#weighted_match_calculators ⇒ Object
23
24
25
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 23
def weighted_match_calculators
@patterns
end
|