Module: NBA::DraftHistory

Defined in:
lib/nba/draft_history.rb

Overview

Provides methods to retrieve draft history

Constant Summary collapse

DRAFT_HISTORY =

Result set name for draft history

Returns:

  • (String)

    the result set name

"DraftHistory".freeze

Class Method Summary collapse

Class Method Details

.all(season: nil, league: League::NBA, client: CLIENT) ⇒ Collection

Retrieves all draft picks for a season

Examples:

picks = NBA::DraftHistory.all(season: 2023)
picks.each { |p| puts "#{p.overall_pick}. #{p.player_name}" }

Parameters:

  • season (Integer) (defaults to: nil)

    the draft year

  • league (String, League) (defaults to: League::NBA)

    the league ID or League object (default NBA)

  • client (Client) (defaults to: CLIENT)

    the API client to use

Returns:



24
25
26
27
28
29
# File 'lib/nba/draft_history.rb', line 24

def self.all(season: nil, league: League::NBA, client: CLIENT)
  league_id = Utils.extract_league_id(league)
  path = build_path(season, league_id)
  response = client.get(path)
  parse_response(response)
end

.by_team(team:, season: nil, league: League::NBA, client: CLIENT) ⇒ Collection

Retrieves draft picks for a specific team

Examples:

picks = NBA::DraftHistory.by_team(team: NBA::Team::GSW, season: 2023)
picks.each { |p| puts "#{p.round_number}.#{p.round_pick}: #{p.player_name}" }

Parameters:

  • team (Integer, Team)

    the team ID or Team object

  • season (Integer) (defaults to: nil)

    the draft year

  • league (String, League) (defaults to: League::NBA)

    the league ID or League object (default NBA)

  • client (Client) (defaults to: CLIENT)

    the API client to use

Returns:



42
43
44
45
46
47
# File 'lib/nba/draft_history.rb', line 42

def self.by_team(team:, season: nil, league: League::NBA, client: CLIENT)
  team_id = extract_team_id(team)
  all_picks = all(season: season, league: league, client: client)
  filtered = all_picks.select { |pick| pick.team_id.eql?(team_id) }
  Collection.new(filtered)
end