Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# -*- encoding: utf-8 -*-
require "rexml/document"
doc = nil
filename = ARGV[0]
if ARGV.size == 0
puts "usage: ruby kaken.rb filename"
exit
end
File.open(filename) {|fp|
doc = REXML::Document.new fp
}
h = Hash.new
h.default = 0
i = 0
doc.root.elements.each {|e|
d = REXML::XPath.first(e,"date")
next if d == nil
f = REXML::XPath.first(d,"from")
next if f == nil
year = f.text.to_i
h[year] = h[year] + 1
}
h.to_a.sort{|a,b| (a[0] <=> b[0])}.each{|a|
puts "#{a[0]} #{a[1]}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment