Class: NHLStats::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/nhl_stats/team.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(team_data) ⇒ Team

Returns a new instance of Team.



5
6
7
8
9
# File 'lib/nhl_stats/team.rb', line 5

def initialize(team_data)
  @id = team_data["id"]
  @name = team_data["name"]
  @abbreviation = team_data["abbreviation"]
end

Instance Attribute Details

#abbreviationObject (readonly)

Returns the value of attribute abbreviation.



3
4
5
# File 'lib/nhl_stats/team.rb', line 3

def abbreviation
  @abbreviation
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/nhl_stats/team.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/nhl_stats/team.rb', line 3

def name
  @name
end

Class Method Details

.find(id) ⇒ Object



21
22
23
24
25
# File 'lib/nhl_stats/team.rb', line 21

def self.find(id)
  response = Faraday.get("#{API_ROOT}/teams/#{id}")
  attributes = JSON.parse(response.body).dig("teams", 0)
  new(attributes)
end

.list(params = {}) ⇒ Object



27
28
29
30
31
32
# File 'lib/nhl_stats/team.rb', line 27

def self.list(params = {})
  response = Faraday.get("#{API_ROOT}/teams", params)
  JSON.parse(response.body).
    dig("teams").
    map { |t| NHLStats::Team.new(t) }
end

Instance Method Details

#current_rosterObject



11
12
13
14
# File 'lib/nhl_stats/team.rb', line 11

def current_roster
  response = Faraday.get("#{API_ROOT}/teams/#{id}/roster")
  roster_response_to_players(response)
end

#roster_for_season(season) ⇒ Object



16
17
18
19
# File 'lib/nhl_stats/team.rb', line 16

def roster_for_season(season)
  response = Faraday.get("#{API_ROOT}/teams/#{id}/roster", :season => season)
  roster_response_to_players(response)
end