Class: Kiba::Extend::Transforms::Delete::EmptyFieldValues
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Delete::EmptyFieldValues
- Includes:
- Allable
- Defined in:
- lib/kiba/extend/transforms/delete/empty_field_values.rb
Overview
Note:
Only useful for multi-valued fields
Deletes any empty values from the field. Supports usenull
= true to treat the value of
Kiba::Extend.nullvalue
as empty
Examples
Assuming Kiba::Extend.nullvalue
= %NULLVALUE%
, and input table:
| data |
|------------------|
| abc;;;d e f |
| ;;abc |
| def;;;; |
| ;;;;; |
| ;;;%NULLVALUE%;; |
| |
| nil |
Used in pipeline as:
transform Delete::EmptyFieldValues, fields: [:data], sep: ';'
Results in:
| data |
|-------------|
| abc;d e f |
| abc |
| def |
| |
| %NULLVALUE% |
| |
| nil |
Used in pipeline as:
transform Delete::EmptyFieldValues, fields: [:data], sep: ';', usenull: true
Results in:
| data |
|-----------|
| abc;d e f |
| abc |
| def |
| |
| |
| |
| nil |
Instance Method Summary collapse
-
#initialize(fields:, sep: nil, delim: nil, usenull: false) ⇒ EmptyFieldValues
constructor
A new instance of EmptyFieldValues.
-
#process(row) ⇒ Object
Constructor Details
#initialize(fields:, sep: nil, delim: nil, usenull: false) ⇒ EmptyFieldValues
Note:
sep
will be removed in a future version. DO NOT USE
Returns a new instance of EmptyFieldValues.
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/kiba/extend/transforms/delete/empty_field_values.rb', line 77 def initialize(fields:, sep: nil, delim: nil, usenull: false) @fields = [fields].flatten @usenull = usenull if sep && delim puts %(#{Kiba::Extend.warning_label}: Do not use both `sep` and `delim`. Prefer `delim`) elsif sep puts %(#{Kiba::Extend.warning_label}: The `sep` keyword is being deprecated in a future version. Change it to `delim` in your ETL code.) @delim = sep else @delim = delim || Kiba::Extend.delim end end |
Instance Method Details
#process(row) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/kiba/extend/transforms/delete/empty_field_values.rb', line 92 def process(row) finalize_fields(row) unless fields_set fields.each do |field| val = row.fetch(field) next if val.nil? row[field] = val.split(delim) .compact .reject { |str| Helpers.empty?(str, usenull) } .join(delim) end row end |