Class: Kiba::Extend::Transforms::Fingerprint::FlagChanged
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Fingerprint::FlagChanged
- Defined in:
- lib/kiba/extend/transforms/fingerprint/flag_changed.rb
Overview
Decodes a fingerprint string and compares each decoded field value to the value in the main field. Records the field name for each value with changes in the target field. If all decoded fields match their main fields, the target field is left blank.
See Decode for details on the decoding process.
Notes on examples
### Example 1 - Row 1: fingerprinted values didn’t change - Row 2: :b changed from bee to bees, and :d changed from deer to doe after fingerprint was encoded. :e was changed from nil to an empty string, but because :empty_equals_nil is true by default, this change is not reported - Row 3: :d was removed after fingerprint was encoded.
Example 2
- Shows how Row 2 from Example 1 is treated differently if :empty_equals_nil is set to false
Example 3
- Shows how Row 3 from Example 1 is treated differently if we indicate that :d should be ignored
Instance Method Summary collapse
-
#initialize(fingerprint:, source_fields:, target:, delim: "␟", prefix: "fp", delete_fp: false, ignore_fields: [], empty_equals_nil: true) ⇒ FlagChanged
constructor
A new instance of FlagChanged.
-
#process(row) ⇒ Object
Constructor Details
#initialize(fingerprint:, source_fields:, target:, delim: "␟", prefix: "fp", delete_fp: false, ignore_fields: [], empty_equals_nil: true) ⇒ FlagChanged
Returns a new instance of FlagChanged.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/kiba/extend/transforms/fingerprint/flag_changed.rb', line 145 def initialize(fingerprint:, source_fields:, target:, delim: "␟", prefix: "fp", delete_fp: false, ignore_fields: [], empty_equals_nil: true) @decoder = Decode.new( fingerprint: fingerprint, source_fields: source_fields, delim: delim, prefix: prefix, delete_fp: delete_fp ) @target = target @empty_equals_nil = empty_equals_nil @source_fields = source_fields - [ignore_fields].flatten @target_fields = @source_fields.map do |field| "#{prefix}_#{field}".to_sym end end |
Instance Method Details
#process(row) ⇒ Object
164 165 166 167 168 169 170 171 172 |
# File 'lib/kiba/extend/transforms/fingerprint/flag_changed.rb', line 164 def process(row) row[target] = nil decoder.process(row) changed = record_changes(row) return row if changed.empty? row[target] = changed.join(Kiba::Extend.delim) row end |