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