Skip to content

Instantly share code, notes, and snippets.

@zarkzork
Forked from anonymous/gist:946384
Created April 28, 2011 14:35
Show Gist options
  • Save zarkzork/946461 to your computer and use it in GitHub Desktop.
Save zarkzork/946461 to your computer and use it in GitHub Desktop.
require 'set'
file = File.new("data")
storage = Hash.new {}
file.each_line do |line|
date, key, value = line.split(';')
storage[date][key] = value
end
colunms = []
table = Hash.new []
storage.each do |date, hash|
hash.each do |key, value|
columns.push(key) unless columns.include? key
num = columns.index(key)
table[date][num] = value
end
table[date].map!{|v| v == nil ? 1 : v }
end
print "date"
columns.each { |val|
print ";" + val
}
print "\n"
table.each {|date, array|
print "#{date};#{array.join(';')}\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment