Class: Kiba::Extend::Transforms::Deduplicate::GroupedFieldValues
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Deduplicate::GroupedFieldValues
- Includes:
- SepDeprecatable
- Defined in:
- lib/kiba/extend/transforms/deduplicate/grouped_field_values.rb
Overview
Note:
Tread with caution, as this has not been used much and is not extensively tested
Field value deduplication that is at least semi-safe for use with grouped fields that expect the same number of values for each field in the grouping
Instance Method Summary collapse
-
#initialize(on_field:, sep: nil, delim: nil, grouped_fields: [], ignore_case: false, normalized: false) ⇒ GroupedFieldValues
constructor
A new instance of GroupedFieldValues.
-
#process(row) ⇒ Object
Methods included from SepDeprecatable
Constructor Details
#initialize(on_field:, sep: nil, delim: nil, grouped_fields: [], ignore_case: false, normalized: false) ⇒ GroupedFieldValues
Returns a new instance of GroupedFieldValues.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/kiba/extend/transforms/deduplicate/grouped_field_values.rb', line 139 def initialize(on_field:, sep: nil, delim: nil, grouped_fields: [], ignore_case: false, normalized: false) @field = on_field @other = grouped_fields @delim = usedelim(sepval: sep, delimval: delim, calledby: self) @getter = Kiba::Extend::Transforms::Helpers::FieldValueGetter.new( fields: grouped_fields, discard: %i[nil] ) @ignore_case = ignore_case if normalized @normalizer = Utils::StringNormalizer.new(downcased: false) end end |
Instance Method Details
#process(row) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/kiba/extend/transforms/deduplicate/grouped_field_values.rb', line 155 def process(row) val = row[field] return row if val.blank? vals = comparable_values(row) to_delete = deletable_elements(vals) return row if to_delete.empty? do_deletes(row, to_delete) row end |