Class: Kiba::Extend::Transforms::Normalize::FieldValues
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Normalize::FieldValues
- Defined in:
- lib/kiba/extend/transforms/normalize/field_values.rb
Overview
Note:
The basic functionality of Kiba::Extend::Utils::StringNormalizer is described and tested in that class
Apply Kiba::Extend::Utils::StringNormalizer to the values in the indicated fields
Instance Method Summary collapse
-
#initialize(fields:, targets: nil, delim: nil, mode: nil, replacements: {}, xforms: []) ⇒ FieldValues
constructor
Defined xforms.
-
#process(row) ⇒ Object
Constructor Details
#initialize(fields:, targets: nil, delim: nil, mode: nil, replacements: {}, xforms: []) ⇒ FieldValues
Defined xforms
- :nfkc - ON BY DEFAULT: Applies Unicode compatibility decomposition, followed by canonical composition; See https://unicode.org/reports/tr15/ for more details than you want.
- :replace - ON BY DEFAULT: performs find-and-replace operations
specified in
replacementsparameter - :blank - deletes all spaces and tabs, using Ruby /\pBlank/ regexp
- :lower - downcase the string
- :nonword - removes ALL characters that are not letters, numbers, or underscores
- :punct - removes all characters matching Ruby /\pPunct/ regexp
- :to_ascii - replaces non-ASCII characters with an ASCII approximation, or if none exists, a replacement character which defaults to “?”.
Defined modes
- :cspaceid - replaces weird characters that don’t convert to ASCII properly, :to_ascii, :nonword, :lower
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/kiba/extend/transforms/normalize/field_values.rb', line 111 def initialize(fields:, targets: nil, delim: nil, mode: nil, replacements: {}, xforms: []) @fields = [fields].flatten @targets = if targets targetarr = [targets].flatten unless @fields.length == targetarr.length fail(Kiba::Extend::UnbalancedFieldsTargetsError) end targetarr end @delim = delim @normalizer = Kiba::Extend::Utils::StringNormalizer.new( mode: mode, replacements: replacements, xforms: xforms ) end |
Instance Method Details
#process(row) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/kiba/extend/transforms/normalize/field_values.rb', line 131 def process(row) fields.each_with_index do |field, idx| normalize_field_value(row, field, idx) end row end |