Skip to content

Instantly share code, notes, and snippets.

Created June 22, 2009 00:27
Show Gist options
  • Save anonymous/133733 to your computer and use it in GitHub Desktop.
Save anonymous/133733 to your computer and use it in GitHub Desktop.
# imports institutions from a filemaker exported xml file
require File.dirname(__FILE__) + '/../../config/environment'
require 'rubygems'
require 'hpricot'
# this establishes a mapping between column names in the
# exported filemaker xml and the variable names we'll be using in rails
mapper = {
"institution_key" => :institution_key,
"institution_name" => :institution_name,
"institutionID" => :institution_id
}
doc = open('/Users/vinay/ptl/institutions.xml') { |f| Hpricot.XML(f)}
old_column_names = Array.new
(doc/"FMPXMLRESULT/METADATA/FIELD").each do |field|
old_column_names << field.attributes['NAME']
end
(doc/"FMPXMLRESULT/RESULTSET/ROW").each do |row|
params = Hash.new
(row/'COL').each_with_index do |col, index|
if mapper.has_key?(old_column_names[index])
params[mapper[old_column_names[index]]] = col.at("DATA").inner_html
end
end
params.each do |key, value|
puts "#{key} => #{value}"
end
Institution.create params
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment