Class: ETL::Transform::TypeTransform

Inherits:
Transform
  • Object
show all
Defined in:
lib/etl/transform/type_transform.rb

Overview

Transform from one type to another

Instance Attribute Summary

Attributes inherited from Transform

#configuration, #control, #name

Instance Method Summary collapse

Methods inherited from Transform

benchmarks, transform

Constructor Details

#initialize(control, name, configuration = {}) ⇒ TypeTransform

Initialize the transformer.

Configuration options:

  • :type: The type to convert to. Supported types:

** :string ** :number,:integer ** :float ** :decimal



13
14
15
16
17
# File 'lib/etl/transform/type_transform.rb', line 13

def initialize(control, name, configuration={})
  super
  @type = configuration[:type]
  @significant = configuration[:significant] ||= 0
end

Instance Method Details

#transform(name, value, row) ⇒ Object

Transform the value



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/etl/transform/type_transform.rb', line 19

def transform(name, value, row)
  case @type
  when :string
    value.to_s
  when :number, :integer
    value.to_i
  when :float
    value.to_f
  when :decimal
    BigDecimal.new(value.to_s, @significant)
  else
    raise "Unsupported type: #{@type}"
  end
end