Sha256: 73a1b66010cba93e46e706cc1016c2ca1c65d4ce91015e23bbedc18dab0e1800
Contents?: true
Size: 1.9 KB
Versions: 4
Compression:
Stored size: 1.9 KB
Contents
require_relative "../team.rb" module PlaylyfeClient module V2 class Team < PlaylyfeClient::Team attr_reader :definition, :access, :game_id, :roles, :owner def members @members ||= fill_members end def leaderboards @game.leaderboards.for_teams end private def initialize(team_hash, game) super(game) @id=team_hash[:id] || team_hash["id"] @name=team_hash[:name] || team_hash["name"] @access=team_hash[:access] || team_hash["access"] @game_id=team_hash[:game_id] || team_hash["game_id"] @roles=team_hash[:roles] || team_hash["roles"] @definition=team_hash[:definition] || team_hash["definition"] @created_at=team_hash[:created_at] || team_hash["created_at"] #created_at should be Time instance @created_at=(Time.parse(team_hash[:created] || team_hash["created"]) ) if @created_at.nil? && !(team_hash[:created] || team_hash["created"]).nil? #created_at is string representation of time own=team_hash[:owner] || team_hash["owner"] @owner=nil unless own.nil? || own.empty? @owner=game.players.find(own[:id] || own["id"]) end end def fill_members @members=[] game.connection.get_team_members_hash_array(self.id).each do |player_hash| player=game.players.find(player_hash["id"]) #all players should be listed in game, so if nothing is found raise exception if player.nil? fail PlaylyfeClient::TeamError.new("{\"error\": \"Player not found\", \"error_description\": \"Player '#{player_hash["id"]}' from '#{self.name}'[#{self.id}] team was not found between game.players!\"}") end @members << player end @members end end end end
Version data entries
4 entries across 4 versions & 1 rubygems