Class: Almicube::AssociationProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/almicube/proxy/association_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(ranking, item) ⇒ AssociationProxy

Returns a new instance of AssociationProxy.

Raises:

  • (TypeError)


3
4
5
6
7
# File 'lib/almicube/proxy/association_proxy.rb', line 3

def initialize(ranking, item)
  raise TypeError, "without the Almicube::Ranking as #1 argument" unless ranking.kind_of? Ranking::Base
  @item = item
  @ranking = ranking
end

Instance Method Details

#incr(score = 1) ⇒ Object



17
18
19
# File 'lib/almicube/proxy/association_proxy.rb', line 17

def incr(score = 1)
  @ranking.incr(@item, score)
end

#rankObject



13
14
15
# File 'lib/almicube/proxy/association_proxy.rb', line 13

def rank
  @ranking.rank(@item)
end

#scoreObject



9
10
11
# File 'lib/almicube/proxy/association_proxy.rb', line 9

def score
  @ranking.score(@item)
end

#to_sObject



21
22
23
# File 'lib/almicube/proxy/association_proxy.rb', line 21

def to_s
  "#{@item.to_s}: #{@ranking.key} [#{rank} - #{score}]"
end