Last active
August 29, 2015 13:56
-
-
Save seizemu/9256398 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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