Class: CSVDecision::ScanRow Private
- Inherits:
-
Object
- Object
- CSVDecision::ScanRow
- Defined in:
- lib/csv_decision/scan_row.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.
Data row object indicating which columns are constants versus procs.
Instance Attribute Summary collapse
-
#constants ⇒ Array<Integer>
readonly
private
Column indices for simple constants.
-
#procs ⇒ Array<Integer>
readonly
private
Column indices for Proc objects.
Class Method Summary collapse
-
.eval_matcher(proc:, hash:, value: nil) ⇒ Object
private
Evaluate the cell proc against the column's input value and/or input hash.
-
.scan(column:, matchers:, cell:) ⇒ false, Matchers::Proc
private
Scan the table cell against all matches.
Instance Method Summary collapse
-
#initialize ⇒ ScanRow
constructor
private
A new instance of ScanRow.
-
#match_constants?(row:, scan_cols:) ⇒ Boolean
private
Match cells containing simple constants.
-
#match_procs?(row:, input:) ⇒ Boolean
private
Match cells containing a Proc object.
-
#scan_columns(row:, columns:, matchers:) ⇒ Array
private
Scan all the specified
columns
(e.g., inputs) in the givendata
row using thematchers
array supplied.
Constructor Details
#initialize ⇒ 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.
Returns a new instance of ScanRow
86 87 88 89 |
# File 'lib/csv_decision/scan_row.rb', line 86 def initialize @constants = [] @procs = [] end |
Instance Attribute Details
#constants ⇒ Array<Integer> (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 Column indices for simple constants.
81 82 83 |
# File 'lib/csv_decision/scan_row.rb', line 81 def constants @constants end |
#procs ⇒ Array<Integer> (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 Column indices for Proc objects.
84 85 86 |
# File 'lib/csv_decision/scan_row.rb', line 84 def procs @procs end |
Class Method Details
.eval_matcher(proc:, hash:, value: nil) ⇒ Object
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.
Evaluate the cell proc against the column's input value and/or input hash.
70 71 72 73 74 75 76 77 78 |
# File 'lib/csv_decision/scan_row.rb', line 70 def self.eval_matcher(proc:, hash:, value: nil) function = proc.function # A symbol guard expression just needs to be passed the input hash return function[hash] if proc.type == :guard # All other procs can take one or two args function.arity == 1 ? function[value] : function[value, hash] end |
.scan(column:, matchers:, cell:) ⇒ false, Matchers::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.
Scan the table cell against all matches.
20 21 22 23 24 25 26 27 28 |
# File 'lib/csv_decision/scan_row.rb', line 20 def self.scan(column:, matchers:, cell:) return false if cell == '' proc = scan_matchers(column: column, matchers: matchers, cell: cell) return proc if proc # Must be a simple string constant - this is OK except for a certain column types. invalid_constant?(type: :constant, column: column) end |
Instance Method Details
#match_constants?(row:, scan_cols:) ⇒ 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.
Match cells containing simple constants.
119 120 121 122 123 124 125 |
# File 'lib/csv_decision/scan_row.rb', line 119 def match_constants?(row:, scan_cols:) constants.each do |col| return false unless row[col] == scan_cols[col] end true end |
#match_procs?(row:, input:) ⇒ 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.
Match cells containing a Proc object.
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/csv_decision/scan_row.rb', line 131 def match_procs?(row:, input:) hash = input[:hash] scan_cols = input[:scan_cols] procs.each do |col| match = ScanRow.eval_matcher(proc: row[col], value: scan_cols[col], hash: hash) return false unless match end true end |
#scan_columns(row:, columns:, matchers:) ⇒ Array
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.
Scan all the specified columns
(e.g., inputs) in the given
data
row using the matchers
array supplied.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/csv_decision/scan_row.rb', line 99 def scan_columns(row:, columns:, matchers:) columns.each_pair do |col, column| # An empty input cell matches everything, and so never needs to be scanned next if (cell = row[col]) == '' && column.ins? # If the column is text only then no special matchers need be invoked next @constants << col if column.eval == false # Need to scan the cell against all matchers, and possibly overwrite # the cell contents with a Matchers::Proc. row[col] = scan_cell(column: column, col: col, matchers: matchers, cell: cell) end row end |