Class: Kiba::Extend::Transforms::Copy::Field

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(from:, to:) ⇒ Field

Returns a new instance of Field.

Parameters:

  • from (Symbol)

    Name of field to copy data from

  • to (Symbol)

    Name of field to copy data to



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

Parameters:

  • row (Hash{ Symbol => String, nil })


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