Class: Kiba::Extend::Transforms::Copy::Field
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Copy::Field
- Defined in:
- lib/kiba/extend/transforms/copy/field.rb
Overview
TODO:
Add safe_copy
parameter that will prevent overwrite of existing data in to
Copy the value of a field to another field. If to
field does not yet exist, it is created. Otherwise, it is overwritten with the copied value.
Defined Under Namespace
Classes: MissingFromFieldError
Instance Method Summary collapse
-
#initialize(from:, to:) ⇒ Field
constructor
A new instance of Field.
-
#process(row) ⇒ Object
Constructor Details
#initialize(from:, to:) ⇒ Field
Returns a new instance of Field.
21 22 23 24 |
# File 'lib/kiba/extend/transforms/copy/field.rb', line 21 def initialize(from:, to:) @from = from @to = to end |
Instance Method Details
#process(row) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/kiba/extend/transforms/copy/field.rb', line 27 def process(row) fail MissingFromFieldError.new(from, row.keys) unless row.key?(from) row[to] = row.fetch(from) row end |