Class: CSVDecision::Matchers Private
- Inherits:
-
Object
- Object
- CSVDecision::Matchers
- Defined in:
- lib/csv_decision/matchers.rb,
lib/csv_decision.rb,
lib/csv_decision/matchers/guard.rb,
lib/csv_decision/matchers/range.rb,
lib/csv_decision/matchers/symbol.rb,
lib/csv_decision/matchers/numeric.rb,
lib/csv_decision/matchers/pattern.rb,
lib/csv_decision/matchers/constant.rb,
lib/csv_decision/matchers/function.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.
Methods to assign a matcher to data cells
Defined Under Namespace
Classes: Constant, Function, Guard, Matcher, Numeric, Pattern, Proc, Range, Symbol
Constant Summary
- NEGATE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Negation sign prefixed to ranges and functions.
'!'
- EQUALS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Cell constants and functions specified by prefixing the value with one of these 3 symbols.
'==|:=|='
- NUMERIC =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Regular expression used to recognise a numeric string with or without a decimal point.
'[-+]?\d*(?<decimal>\.?)\d*'
Instance Attribute Summary collapse
-
#ins ⇒ Array<Matchers::Matcher>
readonly
private
Matchers for the input columns.
-
#outs ⇒ Array<Matchers::Matcher>
readonly
private
Matchers for the output columns.
Class Method Summary collapse
-
.normalize_operator(operator) ⇒ String
private
Normalize the operators which are a variation on equals/assignment.
-
.numeric(value) ⇒ nil, ...
private
Validate a numeric value and convert it to an Integer or BigDecimal if a valid numeric string.
-
.numeric?(value) ⇒ Boolean
private
Return true if value is an Integer or a BigDecimal, false otherwise.
-
.parse(columns:, matchers:, row:) ⇒ Array<(Array, ScanRow)>
private
Parse the supplied input columns for the row supplied using an array of matchers.
-
.regexp(value) ⇒ Regexp
private
All regular expressions used for matching are anchored inside their own non-capturing group.
-
.to_numeric(value) ⇒ nil, ...
private
Convert a numeric string into an Integer or BigDecimal, otherwise return nil.
Instance Method Summary collapse
-
#initialize(options) ⇒ Matchers
constructor
private
A new instance of Matchers.
-
#parse_ins(columns:, row:) ⇒ Array<(Array, ScanRow)>
private
Parse the row's input columns using the input matchers.
-
#parse_outs(columns:, row:) ⇒ Array<(Array, ScanRow)>
private
Parse the row's output columns using the output matchers.
Constructor Details
#initialize(options) ⇒ Matchers
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 Matchers
137 138 139 140 141 |
# File 'lib/csv_decision/matchers.rb', line 137 def initialize() matchers = [:matchers].collect { |klass| klass.new() } @ins = matchers.select(&:ins?) @outs = matchers.select(&:outs?) end |
Instance Attribute Details
#ins ⇒ Array<Matchers::Matcher> (readonly)
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 Matchers for the input columns.
131 132 133 |
# File 'lib/csv_decision/matchers.rb', line 131 def ins @ins end |
#outs ⇒ Array<Matchers::Matcher> (readonly)
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 Matchers for the output columns.
134 135 136 |
# File 'lib/csv_decision/matchers.rb', line 134 def outs @outs end |
Class Method Details
.normalize_operator(operator) ⇒ String
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.
Normalize the operators which are a variation on equals/assignment.
73 74 75 |
# File 'lib/csv_decision/matchers.rb', line 73 def self.normalize_operator(operator) EQUALS_RE.match?(operator) ? '==' : operator end |
.numeric(value) ⇒ nil, ...
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.
Validate a numeric value and convert it to an Integer or BigDecimal if a valid numeric string.
93 94 95 96 97 98 |
# File 'lib/csv_decision/matchers.rb', line 93 def self.numeric(value) return value if numeric?(value) return unless value.is_a?(String) to_numeric(value) end |
.numeric?(value) ⇒ 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.
Return true if value is an Integer or a BigDecimal, false otherwise.
85 86 87 |
# File 'lib/csv_decision/matchers.rb', line 85 def self.numeric?(value) value.is_a?(Integer) || value.is_a?(BigDecimal) end |
.parse(columns:, matchers:, row:) ⇒ Array<(Array, ScanRow)>
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.
Parse the supplied input columns for the row supplied using an array of matchers.
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/csv_decision/matchers.rb', line 117 def self.parse(columns:, matchers:, row:) # Build an array of column indexes requiring simple constant matches, # and a second array of columns requiring special matchers. scan_row = ScanRow.new # Scan the columns in the data row, and build an object to scan this row against # an input hash. # Convert values in the data row if not just a simple constant. row = scan_row.scan_columns(columns: columns, matchers: matchers, row: row) [row, scan_row.freeze] end |
.regexp(value) ⇒ Regexp
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.
All regular expressions used for matching are anchored inside their own non-capturing group.
59 60 61 |
# File 'lib/csv_decision/matchers.rb', line 59 def self.regexp(value) Regexp.new("\\A(?:#{value})\\z").freeze end |
.to_numeric(value) ⇒ nil, ...
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.
Convert a numeric string into an Integer or BigDecimal, otherwise return nil.
104 105 106 107 108 109 |
# File 'lib/csv_decision/matchers.rb', line 104 def self.to_numeric(value) return unless (match = NUMERIC_RE.match(value)) return value.to_i if match['decimal'] == '' BigDecimal(value.chomp('.')) end |
Instance Method Details
#parse_ins(columns:, row:) ⇒ Array<(Array, ScanRow)>
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.
Parse the row's input columns using the input matchers.
148 149 150 |
# File 'lib/csv_decision/matchers.rb', line 148 def parse_ins(columns:, row:) Matchers.parse(columns: columns, matchers: @ins, row: row) end |
#parse_outs(columns:, row:) ⇒ Array<(Array, ScanRow)>
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.
Parse the row's output columns using the output matchers.
157 158 159 |
# File 'lib/csv_decision/matchers.rb', line 157 def parse_outs(columns:, row:) Matchers.parse(columns: columns, matchers: @outs, row: row) end |