Class: Sc2RanksApi::Character

Inherits:
Object
  • Object
show all
Defined in:
lib/sc2ranksapi/character.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Character

Returns a new instance of Character.



7
8
9
10
11
12
13
14
# File 'lib/sc2ranksapi/character.rb', line 7

def initialize(data)
  @achievement_points = data["achievement_points"]
  @name               = data["name"]
  @region             = data["region"]
  @updated_at         = data["updated_at"]

  add_teams data["teams"]
end

Instance Attribute Details

#achievement_pointsObject (readonly)

Returns the value of attribute achievement_points.



5
6
7
# File 'lib/sc2ranksapi/character.rb', line 5

def achievement_points
  @achievement_points
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/sc2ranksapi/character.rb', line 5

def name
  @name
end

#portraitObject (readonly)

Returns the value of attribute portrait.



5
6
7
# File 'lib/sc2ranksapi/character.rb', line 5

def portrait
  @portrait
end

#regionObject (readonly)

Returns the value of attribute region.



5
6
7
# File 'lib/sc2ranksapi/character.rb', line 5

def region
  @region
end

#teamsObject (readonly)

Returns the value of attribute teams.



5
6
7
# File 'lib/sc2ranksapi/character.rb', line 5

def teams
  @teams
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



5
6
7
# File 'lib/sc2ranksapi/character.rb', line 5

def updated_at
  @updated_at
end

Instance Method Details

#add_teams(teams_data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/sc2ranksapi/character.rb', line 16

def add_teams(teams_data)
  @teams = Hash.new if @teams.nil?

  teams_data.each do |team_data|
    team = Team.new(team_data)
    bracket = team_data["bracket"]
    @teams[bracket] = Array.new if @teams[bracket].nil?
    @teams[bracket] << team
  end
end