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
59 60 61 62 |
# File 'lib/csv_decision/scan_row.rb', line 59 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.
54 55 56 |
# File 'lib/csv_decision/scan_row.rb', line 54 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.
57 58 59 |
# File 'lib/csv_decision/scan_row.rb', line 57 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.
43 44 45 46 47 48 49 50 51 |
# File 'lib/csv_decision/scan_row.rb', line 43 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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/csv_decision/scan_row.rb', line 16 def self.scan(column:, matchers:, cell:) matchers.each do |matcher| # Guard function only accepts the same matchers as an output column. next if column.type == :guard && !matcher.outs? if (proc = matcher.matches?(cell)) guard_constant?(type: proc.type, column: column) return proc end end # Must be a simple string constant - this is OK except for a guard column guard_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.
92 93 94 95 96 97 98 |
# File 'lib/csv_decision/scan_row.rb', line 92 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.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/csv_decision/scan_row.rb', line 104 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.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/csv_decision/scan_row.rb', line 72 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 |