Skip to content

Instantly share code, notes, and snippets.

@r00k
Forked from anonymous/gist:133733
Created June 22, 2009 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r00k/133735 to your computer and use it in GitHub Desktop.
Save r00k/133735 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
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