Class: Kiba::Extend::Transforms::Delete::Fields

Inherits:
Object
  • Object
show all
Defined in:
lib/kiba/extend/transforms/delete/fields.rb

Overview

Deletes field(s) passed in fields parameter.

Examples

Input table:

| a | b | c |
|---+---+---|
| 1 | 2 | 3 |

Used in pipeline as:

transform Delete::Fields, fields: %i[a c]

Results in:

| b |
|---|
| 2 |

Used in pipeline as:

transform Delete::Fields, fields: :b

Results in:

| a | c |
|---+---|
| 1 | 3 |

Instance Method Summary collapse

Constructor Details

#initialize(fields:) ⇒ Fields

Returns a new instance of Fields.

Parameters:

  • fields (Array<Symbol>, Symbol)

    field(s) to delete from



49
50
51
# File 'lib/kiba/extend/transforms/delete/fields.rb', line 49

def initialize(fields:)
  @fields = [fields].flatten
end

Instance Method Details

#process(row) ⇒ Object

Parameters:

  • row (Hash{ Symbol => String, nil })


54
55
56
57
# File 'lib/kiba/extend/transforms/delete/fields.rb', line 54

def process(row)
  fields.each { |name| row.delete(name) }
  row
end