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

- old
+ new

@@ -14,18 +14,16 @@ private_constant :EXPLICIT_COMPARISON IMPLICIT_COMPARISON = Matchers.regexp("(?<comparator>=~|!~|!=)?\\s*(?<value>\\S.*)") private_constant :IMPLICIT_COMPARISON - # rubocop: disable Style/DoubleNegation PATTERN_LAMBDAS = { - '!=' => proc { |pattern, value| pattern != value }.freeze, - '=~' => proc { |pattern, value| !!pattern.match(value) }.freeze, - '!~' => proc { |pattern, value| !pattern.match(value) }.freeze + '!=' => proc { |pattern, value| pattern != value }.freeze, + '=~' => proc { |pattern, value| pattern.match?(value) }.freeze, + '!~' => proc { |pattern, value| !pattern.match?(value) }.freeze }.freeze private_constant :PATTERN_LAMBDAS - # rubocop: enable Style/DoubleNegation def self.regexp?(cell:, explicit:) # By default a regexp pattern must use an explicit comparator match = explicit ? EXPLICIT_COMPARISON.match(cell) : IMPLICIT_COMPARISON.match(cell) return false if match.nil? @@ -77,19 +75,19 @@ Proc.new(type: :proc, function: PATTERN_LAMBDAS[comparator].curry[pattern].freeze) end # @param options [Hash{Symbol=>Object}] Used to determine the value of regexp_implicit:. def initialize(options = {}) - # By default regexp's must have an explicit comparator + # By default regexp's must have an explicit comparator. @regexp_explicit = !options[:regexp_implicit] end # Recognise a regular expression pattern - e.g., +=~ on|off+ or +!~ OPT.*+. # If the option regexp_implicit: true has been set, then cells may omit the +=~+ comparator # so long as they contain non-word characters typically used in regular expressions such as # +*+ and +.+. - # @param (see Matchers::Matcher#matches?) - # @return (see Matchers::Matcher#matches?) + # @param (see Matcher#matches?) + # @return (see Matcher#matches?) def matches?(cell) Pattern.matches?(cell, regexp_explicit: @regexp_explicit) end end end \ No newline at end of file