Skip to content

Instantly share code, notes, and snippets.

@artm
Created February 28, 2013 09:37
Show Gist options
  • Save artm/5055521 to your computer and use it in GitHub Desktop.
Save artm/5055521 to your computer and use it in GitHub Desktop.
# I have something like:
def map_stream source, destination, options_and_mapping
option1 = options_and_mapping.delete :option1
quiet = options_and_mapping.delete :quiet
source.each do |input_record|
output_record = map_record input_record, options_and_mapping
some_extra_operation(output_record,option1) if option1
@logger.info("mapped record #{input_record} to #{output_record}") unless quiet
destination.insert output_record
end
end
# and I use it like:
map_stream db1[query], db2[table1],
# options
quiet: true,
# fields map
xptr: :external_pointer,
nmbr: :item_number
spreadsheet = CSV.open(excel_import_file, headers: true, header_converters: :symbol)
map_stream spreadsheet, db2[table2],
# options
option1: 42,
# fields map
pop: :population,
mr: :mortality_rate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment