Class: CSVDecision::Matchers::Range

Inherits:
Matcher
  • Object
show all
Defined in:
lib/csv_decision/matchers/range.rb

Overview

Match cell against a Ruby-like range

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

#initialize

Constructor Details

This class inherits a constructor from CSVDecision::Matchers::Matcher

Class Method Details

.matches?(cell) ⇒ 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.

Parameters:

  • cell (String)

    Data row cell.

Returns:

  • (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.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/csv_decision/matchers/range.rb', line 69

def self.matches?(cell)
  if (match = NUMERIC_RANGE.match(cell))
    return range_proc(match: match, coerce: :to_numeric)
  end

  if (match = ALNUM_RANGE.match(cell))
    return range_proc(match: match)
  end

  false
end

Instance Method Details

#matches?(cell) ⇒ false, CSVDecision::Proc

Range expression - e.g., 0...10 or a..z

Parameters:

  • cell (String)

    Data row cell.

Returns:

  • (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.



84
85
86
# File 'lib/csv_decision/matchers/range.rb', line 84

def matches?(cell)
  Range.matches?(cell)
end