Class: Fatboy::Popularity

Inherits:
Object
  • Object
show all
Defined in:
lib/fatboy/popularity.rb

Overview

This class is used to query how popular something is.

Instance Method Summary collapse

Constructor Details

#initialize(model, redis) ⇒ Popularity

We always pass in a redis


8
9
10
11
# File 'lib/fatboy/popularity.rb', line 8

def initialize(model, redis)
  @redis = redis
  @model_name  = model.to_s
end

Instance Method Details

#day(time) ⇒ Object

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

* +time+: A Datetime or Time in the day you wish to query.

25
26
27
28
29
30
# 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) ⇒ Object

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

16
17
18
19
20
# 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) ⇒ Object

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

* +time+: A time within the month you wish to query.

35
36
37
38
39
# 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_hourObject

Get a Fatboy::TimeBasedPopularity for this hour.


51
52
53
# File 'lib/fatboy/popularity.rb', line 51

def this_hour
  hour(Time.now)
end

#this_monthObject

Get a Fatboy::TimeBasedPopularity for this month.


61
62
63
# File 'lib/fatboy/popularity.rb', line 61

def this_month
  month(Time.now)
end

#this_yearObject

Get a Fatboy::TimeBasedPopularity for this year.


66
67
68
# File 'lib/fatboy/popularity.rb', line 66

def this_year
  year(Time.now)
end

#todayObject

Get a Fatboy::TimeBasedPopularity for this day.


56
57
58
# File 'lib/fatboy/popularity.rb', line 56

def today
  day(Time.now)
end

#year(time) ⇒ Object

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

* +time+: A DateTime or Time in the year you wish to query.

44
45
46
47
48
# 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