-
-
Save r00k/133735 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
COLUMN_MAP = { | |
"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 = [] | |
(doc/"FMPXMLRESULT/METADATA/FIELD").each do |field| | |
@old_column_names << field.attributes['NAME'] | |
end | |
(doc/"FMPXMLRESULT/RESULTSET/ROW").each do |row| | |
attributes = parse_attributes(row) | |
p params | |
Institution.create params | |
end | |
def parse_attributes(row) | |
attributes = {} | |
(row/'COL').each_with_index do |col, index| | |
old_column_name = @old_column_names[index] | |
new_column_name = COLUMN_MAP[old_column_name] | |
if COLUMN_MAP[old_column_name] | |
attributes[new_column_name] = col.at("DATA").inner_html | |
end | |
end | |
attributes | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment