Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created August 6, 2014 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaityo256/d3b04c0421a35ac0691d to your computer and use it in GitHub Desktop.
Save kaityo256/d3b04c0421a35ac0691d to your computer and use it in GitHub Desktop.
# -*- 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