Files
danbooru/app/logical/post_sets/popular.rb
r888888888 fad0ab7c93 fixes #2133
2014-04-16 17:43:34 -07:00

49 lines
844 B
Ruby

module PostSets
class Popular < PostSets::Base
attr_reader :date, :scale
def initialize(date, scale)
@date = date.blank? ? Time.zone.now : Time.zone.parse(date)
@scale = scale
end
def posts
::Post.where("created_at between ? and ?", min_date.beginning_of_day, max_date.end_of_day).order("score desc").limit(limit)
end
def limit
CurrentUser.user.per_page
end
def min_date
case scale
when "week"
date.beginning_of_week
when "month"
date.beginning_of_month
else
date
end
end
def max_date
case scale
when "week"
date.end_of_week
when "month"
date.end_of_month
else
date
end
end
def presenter
::PostSetPresenters::Popular.new(self)
end
end
end