Class: Kiba::Extend::Transforms::Prepend::ToFieldValue
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Prepend::ToFieldValue
- Defined in:
- lib/kiba/extend/transforms/prepend/to_field_value.rb
Overview
Adds the specified value to the specified field
If target field value is blank, it is left blank
Instance Method Summary collapse
-
#initialize(field:, value:, multival: false, delim: Kiba::Extend.delim) ⇒ ToFieldValue
constructor
A new instance of ToFieldValue.
-
#process(row) ⇒ Object
Constructor Details
#initialize(field:, value:, multival: false, delim: Kiba::Extend.delim) ⇒ ToFieldValue
Note:
mvdelim
argument is deprecated and replaced by multival
and delim
Returns a new instance of ToFieldValue.
58 59 60 61 62 63 64 |
# File 'lib/kiba/extend/transforms/prepend/to_field_value.rb', line 58 def initialize(field:, value:, multival: false, delim: Kiba::Extend.delim) @field = field @value = value @multival = multival @delim = delim end |
Instance Method Details
#process(row) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/kiba/extend/transforms/prepend/to_field_value.rb', line 67 def process(row) fieldval = row.fetch(field, nil) return row if fieldval.blank? fieldvals = multival ? fieldval.split(delim) : [fieldval] row[field] = fieldvals.map do |fieldval| "#{value}#{fieldval}" end.join(delim) row end |