Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created April 11, 2009 09:18
Show Gist options
  • Save jubishop/93510 to your computer and use it in GitHub Desktop.
Save jubishop/93510 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
lines = STDIN.readlines.map{|line| line.strip }
lines.delete_if{|line| line.empty?}
items = Hash.new
line = lines[0]
items[line] ||= Array.new
curItem = items[line]
raise "Line 2 isn't a {" unless lines[1] == "{"
i = 2
while(i < lines.length-1) do
line = lines[i]
if line == "}"
i += 1
line = lines[i]
items[line] ||= Array.new
curItem = items[line]
i += 1
else
curItem.push(line)
end
i += 1
end
puts items.keys.sort.map{|key|
"#{key}\n{\n " + items[key].sort.join("\n ") + "\n}"
}.join("\n\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment