Created
June 22, 2009 00:27
-
-
Save anonymous/133733 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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