Class: Kiba::Extend::Transforms::Fingerprint::Add

Inherits:
Object
  • Object
show all
Defined in:
lib/kiba/extend/transforms/fingerprint/add.rb

Overview

Note:

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'

Since:

  • 2.7.1.65

Instance Method Summary collapse

Constructor Details

#initialize(fields:, target:, delim: "␟", override_app_delim_check: false) ⇒ Add

Returns a new instance of Add.

Parameters:

  • fields (Array<Symbol>)

    fields whose values should be used in fingerprint

  • delim (String) (defaults to: "␟")

    used to join field values into a hashable string. The default value is U+241F / E2 90 9F / Symbol for Unit Separator.

  • target (Symbol)

    field in which fingerprint hash should inserted

  • override_app_delim_check (Boolean) (defaults to: false)

    if true, will let you create a fingerprint with a delim that contains or is contained by Kiba::Extend.delim or Kiba::Extend.sgdelim. Setting this to true if you are supplying a non-default delimter is dangerous and could result in un-decodeable fingerprints.

Raises:

Since:

  • 2.7.1.65



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

Parameters:

  • row (Hash{ Symbol => String, nil })

Raises:

  • (DelimiterInValueError)

    if the value of any field used to generate a fingerprint contains the fingerprint delimiter

Since:

  • 2.7.1.65



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