Class: FlatFileResolver

Inherits:
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.



187
188
189
190
191
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 187

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.



201
202
203
204
205
206
207
208
209
210
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 201

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