class CSVDecision::Matchers::Constant

Cell constant matcher - e.g., := true, = nil.

Constants

EXPRESSION

Cell constant expression specified by prefixing the value with one of the three equality symbols.

NON_NUMERIC

rubocop: disable Lint/BooleanSymbol Non-numeric constants recognised by CSV Decision.

Public Class Methods

matches?(cell) click to toggle source

@param (see Matchers::Matcher#matches?) @return (see Matchers::Matcher#matches?) @api private

# File lib/csv_decision/matchers/constant.rb, line 31
def self.matches?(cell)
  return false unless (match = EXPRESSION.match(cell))

  proc = non_numeric?(match)
  return proc if proc

  numeric?(match)
end

Private Class Methods

non_numeric?(match) click to toggle source
# File lib/csv_decision/matchers/constant.rb, line 52
def self.non_numeric?(match)
  name = match['value'].to_sym
  return false unless NON_NUMERIC.key?(name)

  proc(function: NON_NUMERIC[name])
end
numeric?(match) click to toggle source
# File lib/csv_decision/matchers/constant.rb, line 45
def self.numeric?(match)
  return false unless (value = Matchers.to_numeric(match['value']))

  proc(function: value)
end
proc(function:) click to toggle source
# File lib/csv_decision/matchers/constant.rb, line 40
def self.proc(function:)
  Matchers::Proc.new(type: :constant, function: function)
end

Public Instance Methods

matches?(cell) click to toggle source

If a constant expression returns a Proc of type :constant,

otherwise return false.

(see Matcher#matches?)

# File lib/csv_decision/matchers/constant.rb, line 64
def matches?(cell)
  Matchers::Constant.matches?(cell)
end
outs?() click to toggle source

(see Matcher#outs?)

# File lib/csv_decision/matchers/constant.rb, line 69
def outs?
  true
end