Skip to content

Instantly share code, notes, and snippets.

@carlzulauf
Last active December 31, 2015 19:09
Show Gist options
  • Save carlzulauf/8032029 to your computer and use it in GitHub Desktop.
Save carlzulauf/8032029 to your computer and use it in GitHub Desktop.
require 'csv'
head = <<-HEAD
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
HEAD
foot = <<-FOOT
</data-set>
FOOT
def record(action, site, vendor, ap)
<<-RECORD
<record>
<Action>#{action}</Action>
<SiteID>#{site}</SiteID>
<VendorID>#{vendor}</VendorID>
<APCode>#{ap}</APCode>
</record>
RECORD
end
File.open("Vendor.xml", "w") do |file|
file << head
CSV.foreach("import.csv", headers: true) do |row|
file << record(row[0].strip, row[1].strip, row[2].strip, row[3].strip)
end
file << foot
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment