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
22
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 12
def method_missing(match_payload, *patterns, &block)
name_string = match_payload.to_s
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
48
49
50
51
52
53
54
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 48
def calculate_matches_for(result)
returning CalculatedMatchCollection.new do |collection|
weighted_match_calculators.each do |pattern|
collection << pattern.match(result)
end
end
end
|
#execute_hook_for(symbol, input) ⇒ Object
28
29
30
31
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 28
def execute_hook_for(symbol, input)
callback = @menu_callbacks[symbol]
callback.call input if callback
end
|
#on_failure(&block) ⇒ Object
43
44
45
46
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 43
def on_failure(&block)
raise LocalJumpError, "Must supply a block!" unless block_given?
@menu_callbacks[:failure] = block
end
|
#on_invalid(&block) ⇒ Object
33
34
35
36
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 33
def on_invalid(&block)
raise LocalJumpError, "Must supply a block!" unless block_given?
@menu_callbacks[:invalid] = block
end
|
#on_premature_timeout(&block) ⇒ Object
38
39
40
41
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 38
def on_premature_timeout(&block)
raise LocalJumpError, "Must supply a block!" unless block_given?
@menu_callbacks[:premature_timeout] = block
end
|
#weighted_match_calculators ⇒ Object
24
25
26
|
# File 'lib/adhearsion/voip/menu_state_machine/menu_builder.rb', line 24
def weighted_match_calculators
@patterns
end
|