Class: Fatboy::ViewedItem

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#idObject (readonly)

Id of the model contained this this ViewedItem



16
17
18
# File 'lib/fatboy/viewed_item.rb', line 16

def id
  @id
end

#rankObject (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

#viewsObject (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