Class: ETL::Transform::SplitFieldsTransform
- Defined in:
- lib/etl/transform/split_fields_transform.rb
Instance Attribute Summary collapse
-
#delimiter ⇒ Object
readonly
Returns the value of attribute delimiter.
-
#new_fields ⇒ Object
readonly
Returns the value of attribute new_fields.
Attributes inherited from Transform
#configuration, #control, #name
Instance Method Summary collapse
-
#initialize(control, name, configuration) ⇒ SplitFieldsTransform
constructor
A new instance of SplitFieldsTransform.
- #transform(name, value, row) ⇒ Object
Methods inherited from 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
#delimiter ⇒ Object (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_fields ⇒ Object (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 |