lib/csv_decision/matchers/numeric.rb in csv_decision-0.1.0 vs lib/csv_decision/matchers/numeric.rb in csv_decision-0.2.0

- old
+ new

@@ -6,13 +6,13 @@ # See LICENSE and README.md for details. module CSVDecision # Methods to assign a matcher to data cells. # @api private class Matchers - # Recognise numeric comparison expressions - e.g., +> 100+ or +!= 0+ + # Recognise numeric comparison expressions - e.g., +> 100+ or +!= 0+. class Numeric < Matcher - # For example: >= 100 or != 0 + # For example: +>= 100+ or +!= 0+. COMPARISON = /\A(?<comparator><=|>=|<|>|!=)\s*(?<value>\S.*)\z/ private_constant :COMPARISON # Coerce the input value to a numeric representation before invoking the comparison. # If the coercion fails, it will produce a nil value which always fails to match. @@ -23,12 +23,11 @@ '<=' => proc { |numeric_cell, value| Matchers.numeric(value)&.<= numeric_cell }, '!=' => proc { |numeric_cell, value| Matchers.numeric(value)&.!= numeric_cell } }.freeze private_constant :COMPARATORS - # @param (see Matchers::Matcher#matches?) - # @return (see Matchers::Matcher#matches?) + # (see Matcher#matches?) def self.matches?(cell) match = COMPARISON.match(cell) return false unless match numeric_cell = Matchers.to_numeric(match['value']) @@ -37,11 +36,10 @@ comparator = match['comparator'] Matchers::Proc.new(type: :proc, function: COMPARATORS[comparator].curry[numeric_cell].freeze) end - # @param (see Matchers::Matcher#matches?) - # @return (see Matchers::Matcher#matches?) + # (see Matcher#matches?) def matches?(cell) Numeric.matches?(cell) end end end \ No newline at end of file