Class: CSVDecision::ScanRow
- Inherits:
-
Object
- Object
- CSVDecision::ScanRow
- Defined in:
- lib/csv_decision/scan_row.rb
Overview
Data row object indicating which columns are constants versus procs.
Instance Attribute Summary collapse
-
#constants ⇒ Array<Integer>
readonly
Column indices for simple constants.
-
#procs ⇒ Array<Integer>
readonly
Column indices for Proc objects.
Instance Method Summary collapse
-
#initialize ⇒ ScanRow
constructor
A new instance of ScanRow.
- #match_constants?(row:, scan_cols:) ⇒ Boolean
- #match_procs?(row:, input:) ⇒ Boolean
-
#scan_columns(row:, columns:, matchers:) ⇒ Array
Scan all the specified
columns
(e.g., inputs) in the givendata
row using thematchers
array supplied.
Constructor Details
#initialize ⇒ ScanRow
Returns a new instance of ScanRow
17 18 19 20 |
# File 'lib/csv_decision/scan_row.rb', line 17 def initialize @constants = [] @procs = [] end |
Instance Attribute Details
#constants ⇒ Array<Integer> (readonly)
Returns Column indices for simple constants.
12 13 14 |
# File 'lib/csv_decision/scan_row.rb', line 12 def constants @constants end |
#procs ⇒ Array<Integer> (readonly)
Returns Column indices for Proc objects.
15 16 17 |
# File 'lib/csv_decision/scan_row.rb', line 15 def procs @procs end |
Instance Method Details
#match_constants?(row:, scan_cols:) ⇒ Boolean
45 46 47 48 49 50 51 |
# File 'lib/csv_decision/scan_row.rb', line 45 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
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/csv_decision/scan_row.rb', line 53 def match_procs?(row:, input:) hash = input[:hash] scan_cols = input[:scan_cols] procs.each do |col| match = Decide.eval_matcher(proc: row[col], value: scan_cols[col], hash: hash) return false unless match end true end |
#scan_columns(row:, columns:, matchers:) ⇒ Array
Scan all the specified columns
(e.g., inputs) in the given
data
row using the matchers
array supplied.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/csv_decision/scan_row.rb', line 29 def scan_columns(row:, columns:, matchers:) columns.each_pair do |col, column| # Empty cell matches everything, and so never needs to be scanned next if (cell = row[col]) == '' # If the column is text only then no special matchers need be invoked next @constants << col if column.text_only # Need to scan the cell against all matchers, and possibly overwrite # the cell contents with a proc. row[col] = scan_cell(col: col, matchers: matchers, cell: cell) end row end |