Class: Brawlhalla::API::Ranking

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

Constant Summary collapse

ATTRIBUTES =
%i[
  name brawlhalla_id rating peak_rating tier wins games region global_rank region_rank
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Ranking

Returns a new instance of Ranking.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/brawlhalla/api/ranking.rb', line 21

def initialize(json)
  ATTRIBUTES.each do |attr|
    send("#{attr}=", json[attr])
  end

  legends = json[:legends] || []
  doubles = json[:"2v2"] || []

  @legend_rankings = legends.map { |legend_json| LegendRanking.new(legend_json) }
  @doubles_rankings = doubles.map { |doubles_json| DoublesRanking.new(doubles_json) }
end

Instance Attribute Details

#doubles_rankingsObject (readonly)

Returns the value of attribute doubles_rankings.



14
15
16
# File 'lib/brawlhalla/api/ranking.rb', line 14

def doubles_rankings
  @doubles_rankings
end

#legend_rankingsObject (readonly)

Returns the value of attribute legend_rankings.



14
15
16
# File 'lib/brawlhalla/api/ranking.rb', line 14

def legend_rankings
  @legend_rankings
end

Class Method Details

.find(brawlhalla_id) ⇒ Object



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

def self.find(brawlhalla_id)
  ranking_json = API.client.ranked(brawlhalla_id)
  new(ranking_json)
end