Sha256: 9257e601ea8bdd60117e8d7b1b148f3daa6124be9d16fcdaf2e63cfc1db15bd8
Contents?: true
Size: 1.73 KB
Versions: 2
Compression:
Stored size: 1.73 KB
Contents
module ETL#:nodoc: module Transform#:nodoc: # 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'} class Transform class << self # 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 <tt>transform(value)</tt>. # Any other object will result in a ControlError being raised. def transform(name, value, transforms) # logger.debug "Transforming field #{name}" if transforms.length > 0 transforms.each do |transform| begin case transform when Proc value = transform.call(value) when Transform value = transform.transform(value) else raise ControlError, "Unsupported transform configuration type: #{transform}" end rescue raise TransformError, "Error transforming #{value} with #{transform}" end end value end end attr_reader :control, :configuration # Initialize the transform object def initialize(control, configuration={}) @control = control @configuration = configuration end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
activewarehouse-etl-0.5.0 | lib/etl/transform/transform.rb |
activewarehouse-etl-0.5.1 | lib/etl/transform/transform.rb |