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>
private
Column indices for simple constants.
-
#procs ⇒ Array<Integer>
readonly
private
Column indices for Proc objects.
Class Method Summary collapse
-
.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?(row:, scan_cols:, hash:) ⇒ Boolean
private
Match cells in the input hash against a decision table row.
-
#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
72 73 74 75 |
# File 'lib/csv_decision/scan_row.rb', line 72 def initialize @constants = [] @procs = [] end |
Instance Attribute Details
#constants ⇒ Array<Integer>
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.
67 68 69 |
# File 'lib/csv_decision/scan_row.rb', line 67 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.
70 71 72 |
# File 'lib/csv_decision/scan_row.rb', line 70 def procs @procs end |
Class Method Details
.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.
21 22 23 24 25 26 27 28 29 |
# File 'lib/csv_decision/scan_row.rb', line 21 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?(row:, scan_cols:, hash:) ⇒ 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 in the input hash against a decision table row.
108 109 110 111 112 113 114 115 116 |
# File 'lib/csv_decision/scan_row.rb', line 108 def match?(row:, scan_cols:, hash:) # Check any table row cell constants first, and maybe fail fast... return false if @constants.any? { |col| row[col] != scan_cols[col] } return true if @procs.empty? # These table row cells are Proc objects which need evaluating @procs.all? { |col| row[col].call(value: scan_cols[col], hash: hash) } 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.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/csv_decision/scan_row.rb', line 85 def scan_columns(row:, columns:, matchers:) columns.each_pair do |col, column| cell = row[col] # An empty input cell matches everything, and so never needs to be scanned, # but it cannot be indexed either. next column.indexed = false if cell == '' && column.ins? # If the column is text only then no special matchers need be used. 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 value. row[col] = scan_cell(column: column, col: col, matchers: matchers, cell: cell) end row end |