Created
April 6, 2012 19:03
-
-
Save atljeremy/2322098 to your computer and use it in GitHub Desktop.
Parse XLS Spreadsheet into Multi-Line Hash Using Ruby
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
# Required Gems | |
require "rubygems" | |
require "spreadsheet" | |
def getPixelTrackers | |
main=Hash.new | |
Spreadsheet.open('public/chart.xls') do |book| | |
book.worksheet('Sheet1').each do |row| | |
key = row[0].to_s.sub("\.0", "") | |
trackerHash = { | |
"impression" => row[2], | |
"click" => row[3], | |
"email" => row[4], | |
"phone" => row[5], | |
"coupon" => row[6] | |
} | |
referrerHash = { | |
row[1] => trackerHash | |
} | |
if main.has_key?(key) | |
main[key].merge!(referrerHash) | |
else | |
dmaHash = { key => referrerHash } | |
main = main.merge(dmaHash) | |
end | |
end | |
end | |
puts main | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment