class NHLStats::Team
Attributes
abbreviation[R]
id[R]
name[R]
Public Class Methods
find(id)
click to toggle source
# 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 = {})
click to toggle source
# 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
new(team_data)
click to toggle source
# 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
Public Instance Methods
current_roster()
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
roster_response_to_players(response)
click to toggle source
# File lib/nhl_stats/team.rb, line 36 def roster_response_to_players(response) JSON.parse(response.body).fetch("roster", []).map do |p_data| NHLStats::Player.new(p_data.delete("person").merge(p_data)) end end