Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2011 13:50
Show Gist options
  • Save anonymous/946384 to your computer and use it in GitHub Desktop.
Save anonymous/946384 to your computer and use it in GitHub Desktop.
file = File.new("data")
storage = Hash.new
while (line = file.gets)
arr = line.split(";")
if (storage[arr[0]] == nil)
storage[arr[0]] = Hash.new
end
storage[arr[0]][arr[1]] = arr[2]
end
columns = []
table = Hash.new
storage.each { |skey, svalue|
table[skey] = []
svalue.each { |key,value|
if (columns.index(key) == nil)
columns.push(key)
end
num = columns.index(key)
table[skey][num] = value
}
}
print "date"
columns.each { |val|
print ";" + val
}
print "\n"
table.each {|date, array|
print date + ";"
array.each { |val|
val = 0 if (val == nil)
print val.to_s + ";"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment