Class: Kiba::Extend::Transforms::Replace::FieldValueWithStaticMapping
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Replace::FieldValueWithStaticMapping
- Defined in:
- lib/kiba/extend/transforms/replace/field_value_with_static_mapping.rb
Overview
Looks up value of source field in given mapping Hash. Replaces
orignal value with the result.
Optional: put result in new target field; look up multiple values
from a multivalue source field, provide a fallback value if source
value is not found in mapping
Instance Method Summary collapse
-
#initialize(source:, mapping:, target: nil, fallback_val: :orig, delete_source: true, delim: nil) ⇒ FieldValueWithStaticMapping
constructor
A new instance of FieldValueWithStaticMapping.
-
#process(row) ⇒ Object
Constructor Details
#initialize(source:, mapping:, target: nil, fallback_val: :orig, delete_source: true, delim: nil) ⇒ FieldValueWithStaticMapping
Returns a new instance of FieldValueWithStaticMapping.
229 230 231 232 233 234 235 236 237 |
# File 'lib/kiba/extend/transforms/replace/field_value_with_static_mapping.rb', line 229 def initialize(source:, mapping:, target: nil, fallback_val: :orig, delete_source: true, delim: nil) @source = source @target = target || source @mapping = mapping @fallback = fallback_val @del = delete_source @delim = delim end |
Instance Method Details
#process(row) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/kiba/extend/transforms/replace/field_value_with_static_mapping.rb', line 240 def process(row) set_initial_value(row) rowval = row[source] vals = prep_vals(rowval) @fallback_val = get_fallback_vals(vals) row[target] = join_result(result(vals)) row.delete(source) if source != target && del row end |