Module: CSVDecision::Numeric

Defined in:
lib/csv_decision/numeric.rb

Overview

Recognise Ruby-like numeric comparison expressions.

Class Method Summary collapse

Class Method Details

.matches?(cell) ⇒ Boolean, ...

Parameters:

  • cell (String)

    Data row cell.

Returns:

  • (Boolean)
  • (false, CSVDecision::Proc)

    Returns false if this cell is not a match; otherwise returns the CSVDecision::Proc object indicating if this is a constant or some type of function.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/csv_decision/numeric.rb', line 26

def self.matches?(cell)
  match = COMPARISON.match(cell)
  return false unless match

  numeric_cell = Matchers.to_numeric(match['value'])
  return false unless numeric_cell

  comparator = match['comparator']
  Proc.with(type: :proc,
            function: COMPARATORS[comparator].curry[numeric_cell].freeze)
end