Class: CsvPiper::Processors::Copy
- Inherits:
-
Object
- Object
- CsvPiper::Processors::Copy
- Defined in:
- lib/csv_piper/processors/copy.rb
Overview
Use to copy data from source row to transformed hash. Does not add any errors.
Instance Method Summary collapse
-
#initialize(mapping = nil) ⇒ Copy
constructor
A new instance of Copy.
- #process(source, transformed, errors) ⇒ Object
Constructor Details
#initialize(mapping = nil) ⇒ Copy
Returns a new instance of Copy.
10 11 12 13 |
# File 'lib/csv_piper/processors/copy.rb', line 10 def initialize(mapping = nil) mapping = Hash[ mapping.map { |val| [val, val] } ] if mapping.is_a?(Array) @mapping = mapping end |
Instance Method Details
#process(source, transformed, errors) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/csv_piper/processors/copy.rb', line 15 def process(source, transformed, errors) if @mapping.is_a?(Hash) transformed = @mapping.each_with_object(transformed) do |(key, new_key), memo| memo[new_key] = source[key] end else transformed = transformed.merge(source) end [transformed, errors] end |