Class: Kiba::Extend::Transforms::Append::ToFieldValue
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Append::ToFieldValue
- Defined in:
- lib/kiba/extend/transforms/append/to_field_value.rb
Overview
Adds the given value to the end of value of the given field. Does not affect nil/empty field values
Instance Method Summary collapse
-
#initialize(field:, value:, delim: nil) ⇒ ToFieldValue
constructor
A new instance of ToFieldValue.
-
#process(row) ⇒ Object
Constructor Details
#initialize(field:, value:, delim: nil) ⇒ ToFieldValue
Returns a new instance of ToFieldValue.
58 59 60 61 62 |
# File 'lib/kiba/extend/transforms/append/to_field_value.rb', line 58 def initialize(field:, value:, delim: nil) @field = field @value = value @delim = delim end |
Instance Method Details
#process(row) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/kiba/extend/transforms/append/to_field_value.rb', line 65 def process(row) fv = row.fetch(@field, nil) return row if fv.blank? vals = @delim ? fv.split(@delim) : [fv] row[@field] = vals.map { |fieldval| "#{fieldval}#{@value}" } .join(@delim) row end |