Class: Fatboy::ViewedItem
- Inherits:
-
Object
- Object
- Fatboy::ViewedItem
- Defined in:
- lib/fatboy/viewed_item.rb
Overview
The viewed item class provides a (very) simple interface for interacting with views on Models. Almost always obtained from a TimeBasedPopularity, this struct simply shows the id of the model, the number of views, and the rank. NOTE: The highest-ranked item has rank 0. Ranks are 0-indexed.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Id of the model contained this this ViewedItem.
-
#rank ⇒ Object
readonly
The rank, 0 being the most viewed, of this item.
-
#views ⇒ Object
readonly
Amount this ViewedItem has been viewed in a time period.
Instance Method Summary collapse
-
#initialize(id, views, rank) ⇒ ViewedItem
constructor
A new instance of ViewedItem.
Constructor Details
#initialize(id, views, rank) ⇒ ViewedItem
Returns a new instance of ViewedItem.
9 10 11 12 13 |
# File 'lib/fatboy/viewed_item.rb', line 9 def initialize(id, views, rank) @id = id.to_i @views = views.to_i @rank = rank.to_i end |
Instance Attribute Details
#id ⇒ Object (readonly)
Id of the model contained this this ViewedItem
16 17 18 |
# File 'lib/fatboy/viewed_item.rb', line 16 def id @id end |
#rank ⇒ Object (readonly)
The rank, 0 being the most viewed, of this item. The time period was pre-set on construction, typically from a Fatboy::TimeBasedView
25 26 27 |
# File 'lib/fatboy/viewed_item.rb', line 25 def rank @rank end |
#views ⇒ Object (readonly)
Amount this ViewedItem has been viewed in a time period. This time period was pre-set on construction.
20 21 22 |
# File 'lib/fatboy/viewed_item.rb', line 20 def views @views end |