Class: ETL::Transform::Transform
- Inherits:
-
Object
- Object
- ETL::Transform::Transform
- Defined in:
- lib/etl/transform/transform.rb
Overview
Base class for transforms.
A transform converts one value to another value using some sort of algorithm.
A simple transform has two arguments, the field to transform and the name of the transform:
transform :ssn, :sha1
Transforms can also be blocks:
transform(:ssn){ |v| v[0,24] }
Finally, a transform can include a configuration hash:
transform :sex, :decode, {:decode_table_path => 'delimited_decode.txt'}
Direct Known Subclasses
BlockTransform, CalculationTransform, DateToStringTransform, DecodeTransform, DefaultTransform, ForeignKeyLookupTransform, HierarchyLookupTransform, OrdinalizeTransform, Sha1Transform, SplitFieldsTransform, StringToDateTimeTransform, StringToDateTransform, StringToTimeTransform, TrimTransform, TypeTransform
Instance Attribute Summary (collapse)
-
- (Object) configuration
readonly
Returns the value of attribute configuration.
-
- (Object) control
readonly
Returns the value of attribute control.
-
- (Object) name
readonly
Returns the value of attribute name.
Class Method Summary (collapse)
- + (Object) benchmarks
-
+ (Object) transform(name, value, row, transforms)
Transform the specified value using the given transforms.
Instance Method Summary (collapse)
-
- (Transform) initialize(control, name, configuration = {})
constructor
Initialize the transform object with the given control object, field name and configuration hash.
- - (Object) transform(name, value, row)
Constructor Details
- (Transform) initialize(control, name, configuration = {})
Initialize the transform object with the given control object, field name and configuration hash
50 51 52 53 54 |
# File 'lib/etl/transform/transform.rb', line 50 def initialize(control, name, configuration={}) @control = control @name = name @configuration = configuration end |
Instance Attribute Details
- (Object) configuration (readonly)
Returns the value of attribute configuration
46 47 48 |
# File 'lib/etl/transform/transform.rb', line 46 def configuration @configuration end |
- (Object) control (readonly)
Returns the value of attribute control
46 47 48 |
# File 'lib/etl/transform/transform.rb', line 46 def control @control end |
- (Object) name (readonly)
Returns the value of attribute name
46 47 48 |
# File 'lib/etl/transform/transform.rb', line 46 def name @name end |
Class Method Details
+ (Object) benchmarks
41 42 43 |
# File 'lib/etl/transform/transform.rb', line 41 def benchmarks @benchmarks ||= {} end |
+ (Object) transform(name, value, row, transforms)
Transform the specified value using the given transforms. The transforms can either be Proc objects or objects which extend from Transform and implement the method transform(value). Any other object will result in a ControlError being raised.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/etl/transform/transform.rb', line 23 def transform(name, value, row, transforms) transforms.each do |transform| benchmarks[transform.class] ||= 0 benchmarks[transform.class] += Benchmark.realtime do Engine.logger.debug "Transforming field #{name} with #{transform.inspect}" case transform when Proc value = transform.call([name, value, row]) when Transform value = transform.transform(name, value, row) else raise ControlError, "Unsupported transform configuration type: #{transform}" end end end value end |
Instance Method Details
- (Object) transform(name, value, row)
56 57 58 |
# File 'lib/etl/transform/transform.rb', line 56 def transform(name, value, row) raise "transform is an abstract method" end |