Class: Kiba::Extend::Transforms::Fingerprint::Add
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Fingerprint::Add
- Defined in:
- lib/kiba/extend/transforms/fingerprint/add.rb
Overview
The delim
used for this transform must not conflict with your application/project delimiters.
For example, if your delim
setting (for multivalue fields) is |
, this delim
value should not
equal or contain that character. Otherwise, the fingerprint decoder may get confused about what is
a separate field vs. multiple values inside one field, and things will be a mess.
Adds a base64 strict encoded hash to the target field. The value hashed is the values of the specified fields, joined into a string using the given delimiter
Examples
Used in pipeline as:
transform Fingerprint::Add, fields: %i[b c d e], delim: ';;;', target: :fp
Input table:
| a | b | c | d | e |
|-----+-----+-----+------+---|
| ant | bee | nil | deer | |
Results in:
| a | b | c | d | e | fp |
|-----+-----+-----+------+---+----------------------------------|
| ant | bee | nil | deer | | YmVlOzs7bmlsOzs7ZGVlcjs7O2VtcHR5 |
Input table:
| a | b | c | d | e |
|-----+--------+-----+------+---|
| ant | be;;;e | nil | deer | |
Results in an error because column b contains the fingerprint delimiter. If you tried to decode the resulting fingerprint, you would get too many columns and loss of data integrity
Notes
Before field values are joined, the following substitutions are run on all field values:
''
is converted to the string'empty'
nil
is converted to the string'nil'
Instance Method Summary collapse
-
#initialize(fields:, target:, delim: "␟", override_app_delim_check: false) ⇒ Add
constructor
A new instance of Add.
-
#process(row) ⇒ Object
Constructor Details
#initialize(fields:, target:, delim: "␟", override_app_delim_check: false) ⇒ Add
Returns a new instance of Add.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/kiba/extend/transforms/fingerprint/add.rb', line 73 def initialize(fields:, target:, delim: "␟", override_app_delim_check: false) @override_app_delim_check = override_app_delim_check check_delim(delim) @fingerprinter = Kiba::Extend::Utils::FingerprintCreator.new( fields: fields, delim: delim ) @target = target @row_num = 0 end |
Instance Method Details
#process(row) ⇒ Object
88 89 90 91 92 |
# File 'lib/kiba/extend/transforms/fingerprint/add.rb', line 88 def process(row) @row_num += 1 row[target] = get_fingerprint(row) row end |