#!/usr/bin/env ruby
require 'pstore'
@hexe_db = "#{@cache_path}/hexe"
def hexe_get(date)
hexe = 0
PStore.new(@hexe_db).transaction do |db|
hexe = db['hexe'][date.strftime('%Y%m%d')] if db.root?('hexe')
db.abort
end
hexe
end
def hexe_rank( max = 5, sep = ' ', *except )
hexe = Hash::new(0)
@diaries.each_value do |diary|
c = hexe_get(diary.date)
hexe[diary.date.strftime('%Y%m%d')] = [c, diary.title] if c != 0
end
result = []
hexe.sort{|a,b| (a[1][0])<=>(b[1][0])}.reverse.each_with_index do |ary,idx|
break if idx >= max
result << "#{idx+1}.#{CGI::escapeHTML( ary[0].to_s + " " + ary[1][1] )}(#{ary[1][0].to_s})"
end
result.join( sep )
end