Class: Adhearsion::VoIP::RangeMatchCalculator
- Inherits:
-
MatchCalculator
- Object
- MatchCalculator
- Adhearsion::VoIP::RangeMatchCalculator
- Defined in:
- lib/adhearsion/voip/menu_state_machine/matchers.rb
Instance Attribute Summary
Attributes inherited from MatchCalculator
Instance Method Summary collapse
-
#initialize(pattern, match_payload) ⇒ RangeMatchCalculator
constructor
A new instance of RangeMatchCalculator.
- #match(query) ⇒ Object
Methods inherited from MatchCalculator
Constructor Details
#initialize(pattern, match_payload) ⇒ RangeMatchCalculator
Returns a new instance of RangeMatchCalculator.
48 49 50 51 |
# File 'lib/adhearsion/voip/menu_state_machine/matchers.rb', line 48 def initialize(pattern, match_payload) raise unless pattern.first.kind_of?(Numeric) && pattern.last.kind_of?(Numeric) super end |
Instance Method Details
#match(query) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/adhearsion/voip/menu_state_machine/matchers.rb', line 53 def match(query) numerical_query = coerce_to_numeric query if numerical_query exact_match = pattern.include?(numerical_query) ? query : nil potential_matches = numbers_in_range_like numerical_query potential_matches.reject! { |m| m.to_s == exact_match.to_s } if exact_match new_calculated_match :query => query, :exact_matches => exact_match, :potential_matches => potential_matches else CalculatedMatch.failed_match!(pattern, query, match_payload) end end |