Class: Fatboy
- Inherits:
-
Object
- Object
- Fatboy
- Defined in:
- lib/fatboy.rb,
lib/fatboy/helpers.rb,
lib/fatboy/version.rb,
lib/fatboy/popularity.rb,
lib/fatboy/viewed_item.rb,
lib/fatboy/time_based_popularity.rb
Overview
It provides a variety of functionality.
Defined Under Namespace
Modules: Helpers Classes: Popularity, TimeBasedPopularity, ViewedItem
Constant Summary collapse
- HOUR_FORMAT_STR =
Format string we use to store the views per hour
"%Y%m%d%H"- DAY_FORMAT_STR =
Format string we use to store the views per day
"%Y%m%d"- MONTH_FORMAT_STR =
Format string we use to store the views per month
"%Y%m"- YEAR_FORMAT_STR =
Format string we use to store the views per year
"%Y"- VERSION =
Gem version of Fatboy
"0.0.1"
Instance Method Summary collapse
-
#initialize(redis: Redis.new) ⇒ Fatboy
constructor
Create a new Fatboy.
-
#popular(model) ⇒ Object
This method returns a Fatboy::Popularity, the main interface for determining the popularity of your models.
-
#view(obj) ⇒ Object
(also: #[])
Say that you have viewed an object, making the proper records for hour, day, month, and year.
Constructor Details
#initialize(redis: Redis.new) ⇒ Fatboy
Create a new Fatboy. Options:
* +redis:+ : The redis to store views in. By default, Redis.new
13 14 15 |
# File 'lib/fatboy.rb', line 13 def initialize(redis: Redis.new) @redis = redis end |
Instance Method Details
#popular(model) ⇒ Object
This method returns a Fatboy::Popularity, the main interface for determining the popularity of your models. Example:
fatboy.popular(Image)
fatboy.popular("Image")
fatboy.popular(model.class)
37 38 39 |
# File 'lib/fatboy.rb', line 37 def popular(model) Popularity.new(model, @redis) end |
#view(obj) ⇒ Object Also known as: []
Say that you have viewed an object, making the proper records for hour, day, month, and year.
-
model- a model of some sort. Should quack like an ActiveRecord model (that is, responding to .id)
20 21 22 23 24 25 26 |
# File 'lib/fatboy.rb', line 20 def view(obj) throw ArgumentError.new("That doesn't quack like a model!") unless obj.respond_to?(:id) stores = Fatboy::Helpers.all_format(Time.now).map do |time| Fatboy::Helpers.format_store(obj.class.to_s, time) end stores.map{|store| inc_member(store, obj.id)} end |