Sha256: 2a7df0f3c6bbabbcd068adf3fe1bbdde232d3e7e36390216dbe7f01aa7e3ac0a
Contents?: true
Size: 1.21 KB
Versions: 4
Compression:
Stored size: 1.21 KB
Contents
module ETL #:nodoc: module Transform #:nodoc: # Transform which decodes coded values class DecodeTransform < ETL::Transform::Transform attr_accessor :decode_table_path, :decode_table_delimiter, :default_value def initialize(control, configuration={}) super if configuration[:decode_table_path] configuration[:decode_table_path] = File.join(File.dirname(control.file), configuration[:decode_table_path]) end @decode_table_path = (configuration[:decode_table_path] || 'decode.txt') @decode_table_delimiter = (configuration[:decode_table_delimiter] || ':') @default_value = (configuration[:default_value] || 'No Value') end def transform(value) decode_table[value] || default_value end def decode_table unless @decode_table @decode_table = {} open(decode_table_path).each do |line| code, value = line.strip.split(decode_table_delimiter) if code && code.length > 0 @decode_table[code] = value else @default_value = value end end end @decode_table end end end end
Version data entries
4 entries across 4 versions & 1 rubygems