Class: Kiba::Extend::Transforms::Fcar::SplitPrep
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Fcar::SplitPrep
- Defined in:
- lib/kiba/extend/transforms/fcar/split_prep.rb
Overview
Prepares data in the given :orig field for input to split
FCAR process. Applies the indicated splits to the orig
field, writing the results to :split_val field; adds
:sort, :autosplit, and :prepped_row_fingerprint
fields.
Constant Summary collapse
- UNIT_SEP =
Used internally to indicate the places where the value needs to be split, before splitting is actually applied. The U+241F / E2 90 9F / Symbol for Unit Separator is used to avoid clashes with other common delimiter strings that may be present in values
"␟"
Instance Method Summary collapse
-
#close ⇒ Object
-
#initialize(splitters:, orig:, target: :split_val, sort: :sort, indicator: :autosplit, fingerprint: :prepped_row_fingerprint) ⇒ SplitPrep
constructor
A new instance of SplitPrep.
-
#process(row) ⇒ Object
Constructor Details
#initialize(splitters:, orig:, target: :split_val, sort: :sort, indicator: :autosplit, fingerprint: :prepped_row_fingerprint) ⇒ SplitPrep
Returns a new instance of SplitPrep.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/kiba/extend/transforms/fcar/split_prep.rb', line 115 def initialize(splitters:, orig:, target: :split_val, sort: :sort, indicator: :autosplit, fingerprint: :prepped_row_fingerprint) @splitters = splitters.is_a?(Hash) ? splitters.keys : splitters @orig = orig @target = target @sort = sort @indicator = indicator @fingerprint = Fingerprint::Add.new( fields: [:orig, target, sort], target: fingerprint ) @splitinds = splitters.is_a?(Hash) ? splitters : nil @rows = [] end |
Instance Method Details
#close ⇒ Object
144 145 |
# File 'lib/kiba/extend/transforms/fcar/split_prep.rb', line 144 def close = rows.flatten .each { |row| yield fingerprint.process(row) } |
#process(row) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/kiba/extend/transforms/fcar/split_prep.rb', line 132 def process(row) val = row[orig] fail(BlankFcarOrigFieldError) if val.blank? row[:orig] = val row.delete(orig) matchers = splitters.select { |splitter| val.match?(splitter) } rows << prep_rows(row, val, matchers) nil end |