class Fatboy::Popularity

This class is used to query how popular something is.

Public Class Methods

new(model, redis) click to toggle source

We always pass in a redis

# File lib/fatboy/popularity.rb, line 8
def initialize(model, redis)
  @redis = redis
  @model_name  = model.to_s
end

Public Instance Methods

day(time) click to toggle source

Get a Fatboy::TimeBasedPopularity for a specific day in time. Arguments:

* +time+: A Datetime or Time in the day you wish to query.
# File lib/fatboy/popularity.rb, line 25
def day(time)
  fmt_time = Fatboy::Helpers.day_format(time.utc)
  store_name = Fatboy::Helpers.format_store(@model_name, fmt_time)

  Fatboy::TimeBasedPopularity.new(@redis, store_name)
end
hour(time) click to toggle source

Get a Fatboy::TimeBasedPopularity for a specific hour in time. Arguments:

* +time+: a DateTime or Time containing the hour in time you wish to query
# File lib/fatboy/popularity.rb, line 16
def hour(time)
  fmt_tim = Fatboy::Helpers.hour_format(time.utc)
  store_name = Fatboy::Helpers.format_store(@model_name, fmt_tim)
  Fatboy::TimeBasedPopularity.new(@redis, store_name)
end
month(time) click to toggle source

Get a Fatboy::TimeBasedPopularity for a specific month in time. Arguments:

* +time+: A time within the month you wish to query.
# File lib/fatboy/popularity.rb, line 35
def month(time)
  fmt_time = Fatboy::Helpers.month_format(time.utc)
  store_name = Fatboy::Helpers.format_store(@model_name, fmt_time)
  Fatboy::TimeBasedPopularity.new(@redis, store_name)
end
this_hour() click to toggle source

Get a Fatboy::TimeBasedPopularity for this hour.

# File lib/fatboy/popularity.rb, line 51
def this_hour
  hour(Time.now)
end
this_month() click to toggle source

Get a Fatboy::TimeBasedPopularity for this month.

# File lib/fatboy/popularity.rb, line 61
def this_month
  month(Time.now)
end
this_year() click to toggle source

Get a Fatboy::TimeBasedPopularity for this year.

# File lib/fatboy/popularity.rb, line 66
def this_year
  year(Time.now)
end
today() click to toggle source

Get a Fatboy::TimeBasedPopularity for this day.

# File lib/fatboy/popularity.rb, line 56
def today
  day(Time.now)
end
year(time) click to toggle source

Get a Fatboy::TimeBasedPopularity for a specific year in time. Arguments:

* +time+: A DateTime or Time in the year you wish to query.
# File lib/fatboy/popularity.rb, line 44
def year(time)
  fmt_time = Fatboy::Helpers.year_format(time.utc)
  store_name = Fatboy::Helpers.format_store(@model_name, fmt_time)
  Fatboy::TimeBasedPopularity.new(@redis, store_name)
end