Class: CSVDecision::Matchers::Pattern Private
- Defined in:
- lib/csv_decision/matchers/pattern.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Match cell against a regular expression pattern - e.g., =~ hot|col or .OPT.
Class Method Summary collapse
-
.matches?(cell, regexp_explicit:) ⇒ Boolean
private
(see Pattern#matches).
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Pattern
constructor
private
A new instance of Pattern.
-
#matches?(cell) ⇒ false, CSVDecision::Proc
private
Recognise a regular expression pattern - e.g., =~ on|off or !~ OPT.*.
Methods inherited from Matcher
Constructor Details
#initialize(options = {}) ⇒ Pattern
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Pattern
78 79 80 81 |
# File 'lib/csv_decision/matchers/pattern.rb', line 78 def initialize( = {}) # By default regexp's must have an explicit comparator. @regexp_explicit = ![:regexp_implicit] end |
Class Method Details
.matches?(cell, regexp_explicit:) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
(see Pattern#matches)
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/csv_decision/matchers/pattern.rb', line 65 def self.matches?(cell, regexp_explicit:) comparator, value = regexp?(cell: cell, explicit: regexp_explicit) # We could not find a regexp pattern - maybe it's a simple string or something else? return false unless comparator # No need for a regular expression if we have simple string inequality pattern = comparator == '!=' ? value : Matchers.regexp(value) Proc.new(type: :proc, function: PATTERN_LAMBDAS[comparator].curry[pattern].freeze) end |
Instance Method Details
#matches?(cell) ⇒ false, CSVDecision::Proc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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 .
.
89 90 91 |
# File 'lib/csv_decision/matchers/pattern.rb', line 89 def matches?(cell) Pattern.matches?(cell, regexp_explicit: @regexp_explicit) end |