Class: FlatFileResolver

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

Instance Method Summary collapse

Constructor Details

#initialize(file, match_index, result_field_index) ⇒ FlatFileResolver

Initialize the flat file resolver. Expects to open a comma-delimited file. Returns the column with the given result_field_index.

The matches argument is a Hash with the key as the column index to search and the value of the Hash as a String to match exactly. It will only match the first result.



145
146
147
148
149
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 145

def initialize(file, match_index, result_field_index)
  @file = file
  @match_index = match_index
  @result_field_index = result_field_index
end

Instance Method Details

#resolve(value) ⇒ Object

Match the row field from the column indicated by the match_index with the given value and return the field value from the column identified by the result_field_index.



159
160
161
162
163
164
165
166
167
168
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 159

def resolve(value)
  rows.each do |row|
    #puts "checking #{row.inspect} for #{value}"
    if row[@match_index] == value
      #puts "match found!, returning #{row[@result_field_index]}"
      return row[@result_field_index]
    end
  end
  nil
end