Module: NBA::LeagueGameFinder

Defined in:
lib/nba/league_game_finder.rb

Overview

Provides methods to find games based on criteria

Constant Summary collapse

TEAM_GAMES =

Result set name for team games

Returns:

  • (String)

    the result set name

"TeamGameFinderResults".freeze
PLAYER_GAMES =

Result set name for player games

Returns:

  • (String)

    the result set name

"PlayerGameFinderResults".freeze
REGULAR_SEASON =

Season type constant for regular season

Returns:

  • (String)

    the season type

"Regular Season".freeze
PLAYOFFS =

Season type constant for playoffs

Returns:

  • (String)

    the season type

"Playoffs".freeze

Class Method Summary collapse

Class Method Details

.by_player(player:, season: nil, season_type: REGULAR_SEASON, client: CLIENT) ⇒ Collection

Finds games for a player

Examples:

games = NBA::LeagueGameFinder.by_player(player: 201939)
games.each { |g| puts "#{g.game_date}: #{g.matchup} - #{g.pts} pts" }

Parameters:

  • player (Integer, Player)

    the player ID or Player object

  • season (Integer, nil) (defaults to: nil)

    the season year (nil for all seasons)

  • season_type (String) (defaults to: REGULAR_SEASON)

    the season type

  • client (Client) (defaults to: CLIENT)

    the API client to use

Returns:



56
57
58
59
60
61
# File 'lib/nba/league_game_finder.rb', line 56

def self.by_player(player:, season: nil, season_type: REGULAR_SEASON, client: CLIENT)
  player_id = Utils.extract_id(player)
  path = build_player_path(player_id, season, season_type)
  response = client.get(path)
  parse_response(response, PLAYER_GAMES)
end

.by_team(team:, season: nil, season_type: REGULAR_SEASON, client: CLIENT) ⇒ Collection

Finds games for a team

Examples:

games = NBA::LeagueGameFinder.by_team(team: NBA::Team::GSW)
games.each { |g| puts "#{g.game_date}: #{g.matchup} - #{g.wl}" }

Parameters:

  • team (Integer, Team)

    the team ID or Team object

  • season (Integer, nil) (defaults to: nil)

    the season year (nil for all seasons)

  • season_type (String) (defaults to: REGULAR_SEASON)

    the season type

  • client (Client) (defaults to: CLIENT)

    the API client to use

Returns:



38
39
40
41
42
43
# File 'lib/nba/league_game_finder.rb', line 38

def self.by_team(team:, season: nil, season_type: REGULAR_SEASON, client: CLIENT)
  team_id = Utils.extract_id(team)
  path = build_team_path(team_id, season, season_type)
  response = client.get(path)
  parse_response(response, TEAM_GAMES)
end