Class: Kiba::Extend::Transforms::Replace::NormWithMostFrequentlyUsedForm
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Replace::NormWithMostFrequentlyUsedForm
- Defined in:
- lib/kiba/extend/transforms/replace/norm_with_most_frequently_used_form.rb
Overview
Provides the most-frequently used literal form for normalized values.
The examples here will discuss names, but this transform can be applied to any kind of values.
REQUIRES:
- one field having original name values (including all minor variants that are removed by normalization
- one field having the normalized name values
The transform does not care what normalization algorithm was applied to derive the normalized values
Notes on examples below:
- In the “With defaults” example, the normalized form is replaced by the most frequently used form
- In the “With target” example, the most frequently used form is put in the specified target field, leaving original normalized value in place
- When there’s a tie among most frequently-used forms, the first-encountered form is used
Instance Method Summary collapse
-
#close ⇒ Object
-
#initialize(normfield:, nonnormfield:, target: nil) ⇒ NormWithMostFrequentlyUsedForm
constructor
A new instance of NormWithMostFrequentlyUsedForm.
-
#process(row) ⇒ Object
Constructor Details
#initialize(normfield:, nonnormfield:, target: nil) ⇒ NormWithMostFrequentlyUsedForm
Returns a new instance of NormWithMostFrequentlyUsedForm.
101 102 103 104 105 106 107 108 |
# File 'lib/kiba/extend/transforms/replace/norm_with_most_frequently_used_form.rb', line 101 def initialize(normfield:, nonnormfield:, target: nil) @normfield = normfield @nonnormfield = nonnormfield @target = target || normfield @data = {} @rows = [] @lookup = {} end |
Instance Method Details
#close ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/kiba/extend/transforms/replace/norm_with_most_frequently_used_form.rb', line 116 def close populate_lookup rows.each do |row| finalize(row) yield row end end |
#process(row) ⇒ Object
110 111 112 113 114 |
# File 'lib/kiba/extend/transforms/replace/norm_with_most_frequently_used_form.rb', line 110 def process(row) populate_data(row) rows << row nil end |