Class: NHLStats::Team
- Inherits:
-
Object
- Object
- NHLStats::Team
- Defined in:
- lib/nhl_stats/team.rb
Instance Attribute Summary collapse
-
#abbreviation ⇒ Object
readonly
Returns the value of attribute abbreviation.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #current_roster ⇒ Object
-
#initialize(team_data) ⇒ Team
constructor
A new instance of Team.
- #roster_for_season(season) ⇒ Object
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
#abbreviation ⇒ Object (readonly)
Returns the value of attribute abbreviation.
3 4 5 |
# File 'lib/nhl_stats/team.rb', line 3 def abbreviation @abbreviation end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/nhl_stats/team.rb', line 3 def id @id end |
#name ⇒ Object (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 |
Instance Method Details
#current_roster ⇒ Object
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 |