Class: Kiba::Extend::Transforms::FilterRows::FieldPopulated
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::FilterRows::FieldPopulated
- Includes:
- ActionArgumentable
- Defined in:
- lib/kiba/extend/transforms/filter_rows/field_populated.rb
Overview
Keep or reject rows based on whether the given field is populated. Blank strings and nils count as not populated.
Examples
Source data:
{val: 'N'},
{val: 'n'},
{val: 'NN'},
{val: 'NY'},
{val: ''},
{val: nil}
Used in pipeline as:
transform FilterRows::FieldPopulated, action: :keep, field: :val
Resulting data:
{val: 'N'},
{val: 'n'},
{val: 'NN'},
{val: 'NY'}
Used in pipeline as:
transform FilterRows::FieldPopulated, action: :reject, field: :val
Resulting data:
{val: ''},
{val: nil},
Instance Method Summary collapse
-
#initialize(action:, field:) ⇒ FieldPopulated
constructor
A new instance of FieldPopulated.
-
#process(row) ⇒ Object
Constructor Details
#initialize(action:, field:) ⇒ FieldPopulated
Returns a new instance of FieldPopulated.
57 58 59 60 61 |
# File 'lib/kiba/extend/transforms/filter_rows/field_populated.rb', line 57 def initialize(action:, field:) validate_action_argument(action) @action = action @field = field end |
Instance Method Details
#process(row) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/kiba/extend/transforms/filter_rows/field_populated.rb', line 64 def process(row) val = row[field] case action when :keep val.blank? ? nil : row when :reject val.blank? ? row : nil end end |