class CSVDecision::Matchers::Guard
Match cell against a column symbol guard expression - e.g., +>:column.present?+ or +:column == 100.0+.
Constants
- FUNCTION
- GUARD_RE
Column symbol guard expression - e.g., +>:column.present?+ or +:column == 100.0+.
- NEGATION
Negated methods
- NUMERIC_COMPARE
Note: value has already been converted to an Integer or BigDecimal.
- SYMBOL_PROC
- SYMBOL_RE
Column symbol expression - e.g., +>:column+ or +:!column+.
Public Class Methods
matches?(cell)
click to toggle source
(see Matcher#matches?
)
# File lib/csv_decision/matchers/guard.rb, line 123 def self.matches?(cell) proc = symbol_proc(cell) return proc if proc symbol_guard(cell) end
Private Class Methods
guard_proc(match)
click to toggle source
# File lib/csv_decision/matchers/guard.rb, line 86 def self.guard_proc(match) method = method(match) param = match['param'] # If the parameter is a numeric value then use numeric compares rather than string compares. if (value = Matchers.to_numeric(param)) return [NUMERIC_COMPARE[method], value] end # Process a non-numeric method where the param is just a string [non_numeric(method), param] end
method(match)
click to toggle source
# File lib/csv_decision/matchers/guard.rb, line 80 def self.method(match) method = match['method'] match['negate'].present? ? NEGATION[method] : Matchers.normalize_operator(method) end
non_numeric(method)
click to toggle source
# File lib/csv_decision/matchers/guard.rb, line 72 def self.non_numeric(method) proc = FUNCTION[method] return proc if proc proc { |symbol, value, hash| Matchers.compare?(lhs: hash[symbol], compare: method, rhs: value) } end
regexp_match(symbol, value, hash)
click to toggle source
# File lib/csv_decision/matchers/guard.rb, line 51 def self.regexp_match(symbol, value, hash) return false unless value.is_a?(String) data = hash[symbol] data.is_a?(String) && Matchers.regexp(value).match?(data) end
symbol_function(symbol, method, hash)
click to toggle source
# File lib/csv_decision/matchers/guard.rb, line 46 def self.symbol_function(symbol, method, hash) hash[symbol].respond_to?(method) && hash[symbol].send(method) end
symbol_guard(cell)
click to toggle source
# File lib/csv_decision/matchers/guard.rb, line 111 def self.symbol_guard(cell) match = GUARD_RE.match(cell) return false unless match proc, value = guard_proc(match) symbol = match['name'].to_sym Matchers::Proc.new(type: :guard, symbols: symbol, function: proc.curry[symbol][value].freeze) end
symbol_proc(cell)
click to toggle source
# File lib/csv_decision/matchers/guard.rb, line 100 def self.symbol_proc(cell) match = SYMBOL_RE.match(cell) return false unless match method = match['negate'].present? ? '!:' : ':' proc = SYMBOL_PROC[method] symbol = match['name'].to_sym Matchers::Proc.new(type: :guard, symbols: symbol, function: proc.curry[symbol].freeze) end
Public Instance Methods
matches?(cell)
click to toggle source
@param (see Matcher#matches?
) @return (see Matcher#matches?
)
# File lib/csv_decision/matchers/guard.rb, line 132 def matches?(cell) Guard.matches?(cell) end
outs?()
click to toggle source
@return (see Matcher#outs?
)
# File lib/csv_decision/matchers/guard.rb, line 137 def outs? true end