Class: Data::Criteria::NumericComparisonMatcher

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/data/criteria/matcher.rb

Constant Summary collapse

REGEXP =
/\A\s*([><]=?)\s+([+-]?[0-9]*[\.]?[0-9]+)\s*\z/

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ NumericComparisonMatcher

Returns a new instance of NumericComparisonMatcher.



35
36
37
38
39
40
# File 'lib/data/criteria/matcher.rb', line 35

def initialize(expected)
  raise "unsupported format" unless m = REGEXP.match(expected)
  @expected_string = expected
  @op = m[1]
  @expected = BigDecimal(m[2])
end

Instance Method Details

#call(actual) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/data/criteria/matcher.rb', line 42

def call(actual)
  case actual
  when String
    actual == @expected_string
  when Numeric
    actual.send(@op.to_sym, @expected)
  else
    raise "actual=#{actual}(#{actual.class}) is unsupported"
  end
end