Class: Kiba::Extend::Transforms::Explode::RowsFromGroupedMultivalFields
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Explode::RowsFromGroupedMultivalFields
- Defined in:
- lib/kiba/extend/transforms/explode/rows_from_grouped_multival_fields.rb
Overview
Creates a new row for each value position in a multivalued field group. For instance, if the values in “name” and “role” fields repeat together, this will create a row with the first values of “name” and “role”, another row for the second values of “name” and “role”, and so on.
If the number of values in grouped multivalued fields is uneven
(e.g. 3 names, but 2 roles), the missing values in the later
rows will be nil
, or the placeholder string value if given.
Note that:
- If the value of any grouped fields is
nil
or an empty string, that field, for the affected row, is treated like any other field in the row (i.e. not part of the group). - Empty/missing values delimited as such in a multivalued grouped field get treated as empty string values.
Instance Method Summary collapse
-
#initialize(fields:, delim: nil, placeholder: nil) ⇒ RowsFromGroupedMultivalFields
constructor
A new instance of RowsFromGroupedMultivalFields.
-
#process(row) ⇒ Object
Constructor Details
#initialize(fields:, delim: nil, placeholder: nil) ⇒ RowsFromGroupedMultivalFields
Returns a new instance of RowsFromGroupedMultivalFields.
132 133 134 135 136 137 |
# File 'lib/kiba/extend/transforms/explode/rows_from_grouped_multival_fields.rb', line 132 def initialize(fields:, delim: nil, placeholder: nil) @fields = [fields].flatten @delim = delim || Kiba::Extend.delim @placeholder = placeholder @other_fields = nil end |
Instance Method Details
#process(row) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/kiba/extend/transforms/explode/rows_from_grouped_multival_fields.rb', line 140 def process(row) set_other_fields(row) unless other_fields other_field_vals = field_vals(row, other_fields) orig_vals = get_orig_vals(row) handle_unpopulated_vals(orig_vals[true], other_field_vals) split_vals = do_val_splits(orig_vals[false]) if split_vals split_vals.each { |sval| yield other_field_vals.merge(sval) } else yield row end nil end |