Class: Kiba::Extend::Transforms::Clean::EnsureConsistentFields
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Clean::EnsureConsistentFields
- Defined in:
- lib/kiba/extend/transforms/clean/ensure_consistent_fields.rb
Overview
Note:
This transform runs in memory, so for very large sources, it may take a long time or fail.
Ensures each output Hash
/row has the same keys. This is important
for writing out to Destinations::CSV, which expects
all rows to have the same headers
Instance Method Summary collapse
-
#close {|evened_row| ... } ⇒ Object
-
#initialize ⇒ EnsureConsistentFields
constructor
A new instance of EnsureConsistentFields.
-
#process(row) ⇒ Object
Nil.
Constructor Details
#initialize ⇒ EnsureConsistentFields
Returns a new instance of EnsureConsistentFields.
33 34 35 36 |
# File 'lib/kiba/extend/transforms/clean/ensure_consistent_fields.rb', line 33 def initialize @keys = {} @rows = [] end |
Instance Method Details
#close {|evened_row| ... } ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/kiba/extend/transforms/clean/ensure_consistent_fields.rb', line 49 def close @allfields = keys.keys rows.each do |row| evened_row = add_fields(row) yield evened_row end end |
#process(row) ⇒ Object
Returns Nil.
40 41 42 43 44 45 46 |
# File 'lib/kiba/extend/transforms/clean/ensure_consistent_fields.rb', line 40 def process(row) @keys = keys.merge(row.keys .map { |key| [key, nil] } .to_h) @rows << row nil end |