Class: Kiba::Extend::Transforms::Clean::AlphabetizeFieldValues
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Clean::AlphabetizeFieldValues
- Includes:
- Helpers
- Defined in:
- lib/kiba/extend/transforms/clean.rb
Overview
Note:
This transformation does NOT sort the ROWS in a dataset. It sorts values within individual fields of a row
Sorts the multiple values within a field alphabetically
Examples
Input table:
| type |
|------------------------------|
| Person;unmapped;Organization |
| ; |
| nil |
| |
| Person;notmapped |
| %NULLVALUE%;apple |
| oatmeal;%NULLVALUE% |
Used in pipeline as:
transform Clean::AlphabetizeFieldValues,
fields: %i[type],
delim: ';',
usenull: false,
direction: :asc
Results in:
| type |
|------------------------------|
| Organization;Person;unmapped |
| ; |
| nil |
| |
| notmapped;Person |
| apple;%NULLVALUE% |
| %NULLVALUE%;oatmeal |
Used in pipeline as:
transform Clean::AlphabetizeFieldValues,
fields: %i[type],
delim: ';',
usenull: false,
direction: :desc
Results in:
| type |
|------------------------------|
| unmapped;Person;Organization |
| ; |
| nil |
| |
| Person;notmapped |
| %NULLVALUE%;apple |
| oatmeal;%NULLVALUE% |
Used in pipeline as:
transform Clean::AlphabetizeFieldValues,
fields: %i[type],
delim: ';',
usenull: true,
direction: :asc
Results in:
| type |
|------------------------------|
| Organization;Person;unmapped |
| ; |
| nil |
| |
| notmapped;Person |
| apple;%NULLVALUE% |
| oatmeal;%NULLVALUE% |
Used in pipeline as:
transform Clean::AlphabetizeFieldValues,
fields: %i[type],
delim: ';',
usenull: true,
direction: :desc
Results in:
| type |
|------------------------------|
| unmapped;Person;Organization |
| ; |
| nil |
| |
| Person;notmapped |
| %NULLVALUE%;apple |
| %NULLVALUE%;oatmeal |
Instance Method Summary collapse
-
#initialize(fields:, delim:, usenull: false, direction: :asc) ⇒ AlphabetizeFieldValues
constructor
A new instance of AlphabetizeFieldValues.
-
#process(row) ⇒ Object
Methods included from Helpers
Constructor Details
#initialize(fields:, delim:, usenull: false, direction: :asc) ⇒ AlphabetizeFieldValues
Returns a new instance of AlphabetizeFieldValues.
137 138 139 140 141 142 143 144 145 |
# File 'lib/kiba/extend/transforms/clean.rb', line 137 def initialize(fields:, delim:, usenull: false, direction: :asc) @fields = [fields].flatten @delim = delim @usenull = usenull @direction = direction nv = usenull ? Kiba::Extend.nullvalue : nil @value_getter = Helpers::FieldValueGetter.new(fields: fields, delim: delim, treat_as_null: nv) end |
Instance Method Details
#process(row) ⇒ Object
148 149 150 151 152 153 154 155 |
# File 'lib/kiba/extend/transforms/clean.rb', line 148 def process(row) value_getter.call(row).each do |field, val| next unless val[delim] row[field] = sort_values(val.split(delim)).join(delim) end row end |