Class: Kiba::Extend::Transforms::Delete::FieldsExcept
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Delete::FieldsExcept
- Defined in:
- lib/kiba/extend/transforms/delete/fields_except.rb
Overview
Deletes all fields except the one(s) passed in fields
parameter.
Examples
Input table:
| a | b | c |
|---+---+---|
| 1 | 2 | 3 |
Used in pipeline as:
transform Delete::FieldsExcept, fields: %i[a c]
Results in:
| a | c |
|---+---|
| 1 | 3 |
Used in pipeline as:
transform Delete::FieldsExcept, fields: :b
Results in:
| b |
|---|
| 2 |
Defined Under Namespace
Classes: MissingKeywordArgumentError
Instance Method Summary collapse
-
#initialize(keepfields: nil, fields: nil) ⇒ FieldsExcept
constructor
A new instance of FieldsExcept.
-
#process(row) ⇒ Object
Constructor Details
#initialize(keepfields: nil, fields: nil) ⇒ FieldsExcept
Note:
The keepfields
parameter will be deprecated in a future version. Use fields
in new code.
Returns a new instance of FieldsExcept.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/kiba/extend/transforms/delete/fields_except.rb', line 61 def initialize(keepfields: nil, fields: nil) if keepfields && fields puts %(#{Kiba::Extend.warning_label}: Do not use both `keepfields` and `fields`. Defaulting to process using `fields`) @fields = [fields].flatten elsif keepfields puts %(#{Kiba::Extend.warning_label}: The `keepfields` keyword is being deprecated in a future version. Change it to `fields` in your ETL code.) @fields = [keepfields].flatten elsif fields @fields = [fields].flatten else raise MissingKeywordArgumentError end end |
Instance Method Details
#process(row) ⇒ Object
76 77 78 79 80 |
# File 'lib/kiba/extend/transforms/delete/fields_except.rb', line 76 def process(row) deletefields = row.keys - fields deletefields.each { |f| row.delete(f) } row end |