Class: Brawlhalla::API::Player

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

Constant Summary collapse

ATTRIBUTES =
%i[
  brawlhalla_id name xp level xp_percentage games wins damagebomb damagespikeball
  damagesidekick hitsnowball kobomb komine kospikeball kosnowball
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Player

Returns a new instance of Player.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/brawlhalla/api/player.rb', line 24

def initialize(json)
  ATTRIBUTES.each do |attr|
    value = json[attr]
    value = value.to_i if attr.to_s.start_with?('damage')

    send("#{attr}=", value)
  end

  # Fix player name encoding
  @name = @name.encode('iso-8859-1')

  initialize_clan(json)
  initialize_legends(json)
end

Instance Attribute Details

#clanObject (readonly)

Returns the value of attribute clan.



16
17
18
# File 'lib/brawlhalla/api/player.rb', line 16

def clan
  @clan
end

#legend_statsObject (readonly)

Returns the value of attribute legend_stats.



16
17
18
# File 'lib/brawlhalla/api/player.rb', line 16

def legend_stats
  @legend_stats
end

Class Method Details

.find(brawlhalla_id) ⇒ Object



18
19
20
21
22
# File 'lib/brawlhalla/api/player.rb', line 18

def self.find(brawlhalla_id)
  stats_json = API.client.stats(brawlhalla_id)

  new(stats_json)
end

Instance Method Details

#rankingObject



39
40
41
# File 'lib/brawlhalla/api/player.rb', line 39

def ranking
  @ranking ||= Ranking.find(brawlhalla_id)
end