class PlaylyfeClient::V2::Leaderboard
Attributes
cycles[R]
entity_type[R]
metric[R]
scope[R]
Public Class Methods
new(lbd_hash, game)
click to toggle source
Calls superclass method
PlaylyfeClient::Leaderboard::new
# File lib/playlyfe_client/v2/leaderboard.rb, line 11 def initialize(lbd_hash, game) super(game) @id=lbd_hash[:id] || lbd_hash["id"] @name=lbd_hash[:name] || lbd_hash["name"] @entity_type=lbd_hash[:entity_type] || lbd_hash["entity_type"] @metric=lbd_hash[:metric] || lbd_hash["metric"] @scope=lbd_hash[:scope] || lbd_hash["scope"] @cycles=lbd_hash[:cycles] || lbd_hash["cycles"] fill_positions(lbd_hash[:data] || lbd_hash["data"] || []) end
Private Instance Methods
fill_positions(data)
click to toggle source
positions is array of entities If there are 3 entities at rank 4, there will be array with 3 items at positions Positions and positions will be [] Playlyfe have this style of ranking too ( #1, #2, #3, #4, #4, #4, #7)
# File lib/playlyfe_client/v2/leaderboard.rb, line 28 def fill_positions(data) data.each do |pos| rank=(pos[:rank]).to_i - 1 score=pos[:score] || 0 entity= pos[:entity] || nil if @positions[rank].nil? @positions[rank] = [{entity: entity, score: score}] else @positions[rank] << {entity: entity, score: score} end end #fill empty positions with [] @positions.each_with_index {|p,i| @positions[i]=[] if p.nil? } @positions end