Module: NBA::HomePageV2

Defined in:
lib/nba/home_page_v2.rb

Overview

Provides methods to retrieve NBA home page V2 statistics

Constant Summary collapse

STAT_CATEGORIES =

Stat categories available in home page V2

{
  pts: "HomePageStat1",
  reb: "HomePageStat2",
  ast: "HomePageStat3",
  stl: "HomePageStat4",
  fg_pct: "HomePageStat5",
  ft_pct: "HomePageStat6",
  fg3_pct: "HomePageStat7",
  blk: "HomePageStat8"
}.freeze

Class Method Summary collapse

Class Method Details

.all(stat_category:, season: Utils.current_season, season_type: "Regular Season", game_scope: "Season", player_or_team: "Team", player_scope: "All Players", stat_type: "Traditional", league: League::NBA, client: CLIENT) ⇒ Collection

Retrieves home page V2 statistics for a stat category

Examples:

stats = NBA::HomePageV2.all(stat_category: :pts, season: 2023)
stats.each { |s| puts "#{s.rank}. #{s.team_abbreviation}: #{s.value}" }

Parameters:

  • stat_category (Symbol)

    the stat 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, etc.)

  • game_scope (String) (defaults to: "Season")

    the game scope (Season, Yesterday, etc.)

  • player_or_team (String) (defaults to: "Team")

    player or team stats (Player, Team)

  • player_scope (String) (defaults to: "All Players")

    the player scope (All Players, Rookies)

  • stat_type (String) (defaults to: "Traditional")

    the stat type (Traditional, Advanced, etc.)

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

    the league ID or League object

  • client (Client) (defaults to: CLIENT)

    the API client to use

Returns:

  • (Collection)

    a collection of home page stats



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nba/home_page_v2.rb', line 40

def self.all(stat_category:, season: Utils.current_season, season_type: "Regular Season",
  game_scope: "Season", player_or_team: "Team", player_scope: "All Players",
  stat_type: "Traditional", league: League::NBA, client: CLIENT)
  result_set = STAT_CATEGORIES.fetch(stat_category)
  league_id = Utils.extract_league_id(league)
  opts = {season: season, season_type: season_type, game_scope: game_scope,
          player_or_team: player_or_team, player_scope: player_scope,
          stat_type: stat_type, league_id: league_id}
  response = client.get(build_path(opts))
  parse_response(response, result_set, stat_category)
end