Module: NBA::Leaders

Defined in:
lib/nba/leaders.rb

Overview

Provides methods to retrieve NBA statistical leaders

Constant Summary collapse

PTS =

Points per game category

Returns:

  • (String)

    the category code

"PTS".freeze
REB =

Rebounds per game category

Returns:

  • (String)

    the category code

"REB".freeze
AST =

Assists per game category

Returns:

  • (String)

    the category code

"AST".freeze
STL =

Steals per game category

Returns:

  • (String)

    the category code

"STL".freeze
BLK =

Blocks per game category

Returns:

  • (String)

    the category code

"BLK".freeze
FG_PCT =

Field goal percentage category

Returns:

  • (String)

    the category code

"FG_PCT".freeze
FG3_PCT =

Three point percentage category

Returns:

  • (String)

    the category code

"FG3_PCT".freeze
FT_PCT =

Free throw percentage category

Returns:

  • (String)

    the category code

"FT_PCT".freeze
EFF =

Efficiency category

Returns:

  • (String)

    the category code

"EFF".freeze

Class Method Summary collapse

Class Method Details

.find(category:, season: Utils.current_season, season_type: "Regular Season", limit: 10, client: CLIENT) ⇒ Collection

Retrieves league leaders for a statistical category

Examples:

leaders = NBA::Leaders.find(category: NBA::Leaders::PTS)
leaders.each { |leader| puts "#{leader.rank}. #{leader.player_name}: #{leader.value}" }

Parameters:

  • category (String)

    the statistical category (PTS, REB, AST, etc.)

  • season (Integer) (defaults to: Utils.current_season)

    the season year (defaults to current season)

  • season_type (String) (defaults to: "Regular Season")

    the season type (Regular Season, Playoffs)

  • limit (Integer) (defaults to: 10)

    the number of results to return (defaults to 10)

  • client (Client) (defaults to: CLIENT)

    the API client to use

Returns:



55
56
57
58
59
60
# File 'lib/nba/leaders.rb', line 55

def self.find(category:, season: Utils.current_season, season_type: "Regular Season", limit: 10, client: CLIENT)
  per_mode = PERCENTAGE_CATEGORIES.include?(category) ? "Totals" : "PerGame"
  path = "leagueleaders?LeagueID=00&PerMode=#{per_mode}&Scope=S&Season=#{Utils.format_season(season)}" \
         "&SeasonType=#{season_type}&StatCategory=#{category}"
  parse_leaders_response(client.get(path), category, limit)
end