Skip to content

Instantly share code, notes, and snippets.

@seizemu
Last active August 29, 2015 13:56
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 seizemu/9256398 to your computer and use it in GitHub Desktop.
Save seizemu/9256398 to your computer and use it in GitHub Desktop.
require "cgi"
#ファイルの名前
filename = "****"
#ファイルを開く
file = File.open(filename,"r:UTF-8")
#必要なデータを保持する配列
list = []
#ファイルから一行ずつ読み出し
file.each_line do |text|
begin
if text =~ /^ja/
#splitメソッドで改行ごとにわけて配列に代入
data = text.split
#必要な要素を取り出す
h = {title: CGI.unescape(data[1]), count: data[-2]}
#pushメソッドで配列に代入
list.push h
end
#例外処理
rescue Exception => e
p e
end
end
file.close
result = list.sort_by do |i|
i[:count].to_i
end
result.reverse.first(10).each do |i|
puts i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment