Class: Cheer::Leaderboard

Inherits:
Object
  • Object
show all
Defined in:
lib/cheer/leaderboard.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Leaderboard

Returns a new instance of Leaderboard.



4
5
6
7
8
9
# File 'lib/cheer/leaderboard.rb', line 4

def initialize(attributes = {})
  @model_klass    = attributes[:model_klass]
  @rank_evaluator = attributes[:rank_evaluator]

  define_public_methods
end

Instance Method Details

#to_hash(user_limit = 3) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/cheer/leaderboard.rb', line 11

def to_hash(user_limit = 3)
  {
    standing_methods[:current_rank] => self.public_send(standing_methods[:current_rank]),
    standing_methods[:rank_around]  => self.public_send(standing_methods[:rank_around]),
    standing_methods[:top_rankers]  => self.public_send(standing_methods[:top_rankers], user_limit)
  }
end