Skip to content

Instantly share code, notes, and snippets.

@tal
Created May 25, 2010 20:51
Show Gist options
  • Select an option

  • Save tal/413675 to your computer and use it in GitHub Desktop.

Select an option

Save tal/413675 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'pp'
require 'faster_csv'
num = 0
file = "t.csv"
data = []
columns = []
FasterCSV.foreach(file) do |row|
num += 1
if num == 1
columns = row
next
end
hash = {}
columns.each_with_index do |col, i|
next unless col
val = row[i]
setter = hash
sp = col.split('__')
sp.each_with_index do |key, j|
if j == sp.size - 1
setter[key] = val
else
setter[key] ||= {}
setter = setter[key]
end
end
end
data << hash
end
pp data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment