Class: Ethel::Operations::Cast
- Inherits:
-
Ethel::Operation
- Object
- Ethel::Operation
- Ethel::Operations::Cast
- Defined in:
- lib/ethel/operations/cast.rb
Instance Method Summary collapse
-
#initialize(field, new_type) ⇒ Cast
constructor
A new instance of Cast.
- #transform(row) ⇒ Object
Methods inherited from Ethel::Operation
Constructor Details
#initialize(field, new_type) ⇒ Cast
Returns a new instance of Cast.
4 5 6 7 8 9 10 11 |
# File 'lib/ethel/operations/cast.rb', line 4 def initialize(field, new_type) super @original_field = field @field_name = field.name @new_type = new_type @new_field = Field.new(@field_name, :type => @new_type) add_child_operation(AddField.new(@new_field)) end |
Instance Method Details
#transform(row) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ethel/operations/cast.rb', line 13 def transform(row) row = super(row) row[@field_name] = case @new_type when :integer row[@field_name].to_i when :string row[@field_name].to_s end row end |