Module: NBA::CommonTeamYears

Defined in:
lib/nba/common_team_years.rb

Overview

Provides methods to retrieve team year history

Constant Summary collapse

TEAM_YEARS =

Result set name

Returns:

  • (String)

    the result set name

"TeamYears".freeze

Class Method Summary collapse

Class Method Details

.all(client: CLIENT) ⇒ Collection

Retrieves all years a team has participated in the league

Examples:

years = NBA::CommonTeamYears.all
gsw_years = years.select { |y| y.team_id == NBA::Team::GSW }
puts "Warriors have played #{gsw_years.size} seasons"

Parameters:

  • client (Client) (defaults to: CLIENT)

    the API client to use

Returns:



22
23
24
25
26
# File 'lib/nba/common_team_years.rb', line 22

def self.all(client: CLIENT)
  path = "commonteamyears?LeagueID=00"
  response = client.get(path)
  parse_response(response)
end

.find(team:, client: CLIENT) ⇒ Collection

Retrieves years for a specific team

Examples:

years = NBA::CommonTeamYears.find(team: NBA::Team::GSW)
puts "First year: #{years.first.year}, Latest: #{years.last.year}"

Parameters:

  • team (Integer, Team)

    the team ID or Team object

  • client (Client) (defaults to: CLIENT)

    the API client to use

Returns:

  • (Collection)

    a collection of team years for the team



37
38
39
40
41
# File 'lib/nba/common_team_years.rb', line 37

def self.find(team:, client: CLIENT)
  team_id = extract_team_id(team)
  years = all(client: client)
  Collection.new(years.select { |y| y.team_id.eql?(team_id) })
end