Class: Adhearsion::VoIP::RangeMatchCalculator

Inherits:
MatchCalculator show all
Defined in:
lib/adhearsion/voip/menu_state_machine/matchers.rb

Instance Attribute Summary

Attributes inherited from MatchCalculator

#match_payload, #pattern

Instance Method Summary collapse

Methods inherited from MatchCalculator

build_with_pattern, inherited

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