Class: Kiba::Extend::Transforms::FilterRows::FieldEqualTo
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::FilterRows::FieldEqualTo
- Includes:
- ActionArgumentable
- Defined in:
- lib/kiba/extend/transforms/filter_rows/field_equal_to.rb
Overview
Keep or reject rows where the value of the specified field exactly matches the given value
Examples
Source data:
{val: 'N'},
{val: 'n'},
{val: 'NN'},
{val: 'NY'},
{val: ''},
{val: nil}
Used in pipeline as:
transform FilterRows::FieldEqualTo, action: :keep, field: :val, value: 'N'
Resulting data:
{val: 'N'}
Used in pipeline as:
transform FilterRows::FieldEqualTo, action: :reject, field: :val, value: 'N'
Resulting data:
{val: 'n'},
{val: 'NN'},
{val: 'NY'},
{val: ''},
{val: nil}
Instance Method Summary collapse
-
#initialize(action:, field:, value:) ⇒ FieldEqualTo
constructor
A new instance of FieldEqualTo.
-
#process(row) ⇒ Object
Constructor Details
#initialize(action:, field:, value:) ⇒ FieldEqualTo
Returns a new instance of FieldEqualTo.
57 58 59 60 61 62 |
# File 'lib/kiba/extend/transforms/filter_rows/field_equal_to.rb', line 57 def initialize(action:, field:, value:) validate_action_argument(action) @column = field @value = value @action = action end |
Instance Method Details
#process(row) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/kiba/extend/transforms/filter_rows/field_equal_to.rb', line 65 def process(row) case action when :keep (row.fetch(column, nil) == value) ? row : nil when :reject (row.fetch(column, nil) == value) ? nil : row end end |