Class: Cranium::TransformationRecord
- Inherits:
-
Object
- Object
- Cranium::TransformationRecord
- Defined in:
- lib/cranium/transformation_record.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #[](field) ⇒ Object
- #[]=(field, value) ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize(source_fields, target_fields) ⇒ TransformationRecord
constructor
A new instance of TransformationRecord.
- #input_data=(values) ⇒ Object
- #split_field(field, options) ⇒ Object
Constructor Details
#initialize(source_fields, target_fields) ⇒ TransformationRecord
Returns a new instance of TransformationRecord.
7 8 9 |
# File 'lib/cranium/transformation_record.rb', line 7 def initialize(source_fields, target_fields) @source_fields, @target_fields = source_fields, target_fields end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/cranium/transformation_record.rb', line 3 def data @data end |
Instance Method Details
#[](field) ⇒ Object
19 20 21 |
# File 'lib/cranium/transformation_record.rb', line 19 def [](field) @data[field] end |
#[]=(field, value) ⇒ Object
25 26 27 |
# File 'lib/cranium/transformation_record.rb', line 25 def []=(field, value) @data[field] = value end |
#has_key?(key) ⇒ Boolean
41 42 43 |
# File 'lib/cranium/transformation_record.rb', line 41 def has_key?(key) @data.has_key? key end |
#input_data=(values) ⇒ Object
13 14 15 |
# File 'lib/cranium/transformation_record.rb', line 13 def input_data=(values) @data = Hash[@source_fields.zip values] end |
#split_field(field, options) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/cranium/transformation_record.rb', line 31 def split_field(field, ) values = @data[field].split([:by]) [:into].each_with_index do |target_field, index| @data[target_field] = values[index] || [:default_value] || values.last end end |