項目ごとに時系列の何かを集めるテンプレート

よくありそうなパターン。
ソートが無駄。そして美しくない。

# こんな入力を想定
# epoch key data
#
result = {}
while s = gets
  m = s.match(/(\d+)\s+(\w+)\s+(.+)/)
  if m
    result[m[2]] = [] unless result.key?(m[2])
    result[m[2]].push([m[1], m[3]])
  end
end

result.each do |key|
  result[key].sort!{|a,b| a[0] <=> b[1]}
  puts "### #{key}"
  result[key].each do |timeanddata|
    puts "#{timeanddata[0]} #{timeanddata[1]}"
  end
end