Class: ETL::Transform::SplitFieldsTransform

Inherits:
Transform show all
Defined in:
lib/etl/transform/split_fields_transform.rb

Instance Attribute Summary collapse

Attributes inherited from Transform

#configuration, #control, #name

Instance Method Summary collapse

Methods inherited from Transform

benchmarks, transform

Constructor Details

#initialize(control, name, configuration) ⇒ SplitFieldsTransform

Returns a new instance of SplitFieldsTransform.



7
8
9
10
11
# File 'lib/etl/transform/split_fields_transform.rb', line 7

def initialize(control, name, configuration)
  @delimiter = configuration[:delimiter] || ','
  @new_fields = configuration[:new_fields]
  super
end

Instance Attribute Details

#delimiterObject (readonly)

Returns the value of attribute delimiter.



4
5
6
# File 'lib/etl/transform/split_fields_transform.rb', line 4

def delimiter
  @delimiter
end

#new_fieldsObject (readonly)

Returns the value of attribute new_fields.



5
6
7
# File 'lib/etl/transform/split_fields_transform.rb', line 5

def new_fields
  @new_fields
end

Instance Method Details

#transform(name, value, row) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/etl/transform/split_fields_transform.rb', line 13

def transform(name, value, row)
  return nil if row.nil?
  return nil if row[name].nil?

  fields = row[name].split(@delimiter)
  @new_fields.each_with_index do |new, index|
    row[new] = fields[index]
  end

  row[name]
end