class PlaylyfeClient::V2::PlayersLeaderboard

Private Instance Methods

fill_positions(data) click to toggle source
# File lib/playlyfe_client/v2/leaderboard/players_leaderboard.rb, line 9
def fill_positions(data)  
  #preproces data into new_data
  new_data=[]

  data.each do |pos|
    rank=(pos[:rank] || pos["rank"]).to_i
    score=pos[:score] || pos["score"]
    entity= pos[:player] || pos["player"]

    player=game.players.find(entity[:id] || entity["id"])

    #all players should be listed in game, so if nothing is found raise exception
    if player.nil?
      fail PlaylyfeClient::LeaderboardError.new("{\"error\": \"Player not found\", \"error_description\": \"Player '#{entity[:id] || entity["id"]}' from '#{self.name}'[#{self.id}] leaderboard was not found between game.players!\"}")
    end 
      
    new_data << {rank: rank, entity: player, score: score}
  end  
  
  super(new_data)
end