Class: FlatFileResolver
- Inherits:
-
Object
- Object
- FlatFileResolver
- Defined in:
- lib/etl/transform/foreign_key_lookup_transform.rb
Instance Method Summary collapse
-
#initialize(file, match_index, result_field_index) ⇒ FlatFileResolver
constructor
Initialize the flat file resolver.
-
#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.
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.
127 128 129 130 131 |
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 127 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.
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 141 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 |