Class: GameLockerAPI::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/gamelocker_api/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Player

Returns a new instance of Player.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gamelocker_api/player.rb', line 7

def initialize(data)
  self.uuid         = data['id']
  self.name         = data['attributes']['name']
  self.created_at   = data['attributes']['createdAt']

  self.games_played = data['attributes']['stats']['gamesPlayed']
  self.guild_tag    = data['attributes']['stats']['guildTag']
  self.karma_level  = data['attributes']['stats']['karmaLevel']
  self.level        = data['attributes']['stats']['level']
  self.rank_points  = data['attributes']['stats']['rank_points']
  self.skill_tier   = data['attributes']['stats']['skillTier']
  self.wins         = data['attributes']['stats']['wins']
  self.xp           = data['attributes']['stats']['xp']

  calculate_total_games_played
  calculate_loses
  return self
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



3
4
5
# File 'lib/gamelocker_api/player.rb', line 3

def created_at
  @created_at
end

#games_playedObject

Returns the value of attribute games_played.



4
5
6
# File 'lib/gamelocker_api/player.rb', line 4

def games_played
  @games_played
end

#guild_tagObject

Returns the value of attribute guild_tag.



4
5
6
# File 'lib/gamelocker_api/player.rb', line 4

def guild_tag
  @guild_tag
end

#karma_levelObject

Returns the value of attribute karma_level.



4
5
6
# File 'lib/gamelocker_api/player.rb', line 4

def karma_level
  @karma_level
end

#levelObject

Returns the value of attribute level.



4
5
6
# File 'lib/gamelocker_api/player.rb', line 4

def level
  @level
end

#losesObject

Returns the value of attribute loses.



5
6
7
# File 'lib/gamelocker_api/player.rb', line 5

def loses
  @loses
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/gamelocker_api/player.rb', line 3

def name
  @name
end

#rank_pointsObject

Returns the value of attribute rank_points.



4
5
6
# File 'lib/gamelocker_api/player.rb', line 4

def rank_points
  @rank_points
end

#shard_idObject

Returns the value of attribute shard_id.



3
4
5
# File 'lib/gamelocker_api/player.rb', line 3

def shard_id
  @shard_id
end

#skill_tierObject

Returns the value of attribute skill_tier.



4
5
6
# File 'lib/gamelocker_api/player.rb', line 4

def skill_tier
  @skill_tier
end

#total_games_playedObject

Returns the value of attribute total_games_played.



5
6
7
# File 'lib/gamelocker_api/player.rb', line 5

def total_games_played
  @total_games_played
end

#uuidObject

Returns the value of attribute uuid.



3
4
5
# File 'lib/gamelocker_api/player.rb', line 3

def uuid
  @uuid
end

#winsObject

Returns the value of attribute wins.



4
5
6
# File 'lib/gamelocker_api/player.rb', line 4

def wins
  @wins
end

#xpObject

Returns the value of attribute xp.



4
5
6
# File 'lib/gamelocker_api/player.rb', line 4

def xp
  @xp
end

Instance Method Details

#calculate_losesObject



35
36
37
38
39
40
41
42
# File 'lib/gamelocker_api/player.rb', line 35

def calculate_loses
  games = 0
  self.games_played.each do |mode, n|
    games+=n
  end

  self.loses = games-wins
end

#calculate_total_games_playedObject



26
27
28
29
30
31
32
33
# File 'lib/gamelocker_api/player.rb', line 26

def calculate_total_games_played
  games = 0
  self.games_played.each do |mode, n|
    games+=n
  end

  self.total_games_played = games
end