Class: Kiba::Extend::Transforms::Merge::ConstantValues

Inherits:
Object
  • Object
show all
Defined in:
lib/kiba/extend/transforms/merge/constant_values.rb

Overview

Note:

Uses ConstantValue to handle each pair in the constantmap, so check its behavior as well.

Merges the given constant values into the given target fields.

Example

Source data:

{name: 'Weddy'},
{name: 'Kernel', species: 'Numida meleagris'}

Used in pipeline as:

transform Merge::ConstantValues,
  constantmap: {
    species_common: 'guinea fowl',
    species_binomial: 'Numida meleagris'
  }

Results in:

{name: 'Weddy', species_common: 'guinea fowl', species_binomial: 'Numida meleagris' },
{name: 'Kernel', species: 'Numida meleagris', species_common: 'guinea fowl', species_binomial: 'Numida meleagris' }

Since:

  • 2.9.0

Instance Method Summary collapse

Constructor Details

#initialize(constantmap:) ⇒ ConstantValues

Returns a new instance of ConstantValues.

Since:

  • 2.9.0



42
43
44
45
46
# File 'lib/kiba/extend/transforms/merge/constant_values.rb', line 42

def initialize(constantmap:)
  @mergers = constantmap.map do |target, value|
    Merge::ConstantValue.new(target: target, value: value)
  end
end

Instance Method Details

#process(row) ⇒ Object

Parameters:

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

Since:

  • 2.9.0



49
50
51
52
# File 'lib/kiba/extend/transforms/merge/constant_values.rb', line 49

def process(row)
  mergers.each { |merger| merger.process(row) }
  row
end