Module: NBA::DefenseHub

Defined in:
lib/nba/defense_hub.rb

Overview

Provides methods to retrieve NBA defense hub statistics

Constant Summary collapse

STAT_CATEGORIES =

Stat categories available in the defense hub

{
  dreb: "DefenseHubStat1",
  stl: "DefenseHubStat2",
  blk: "DefenseHubStat3",
  def_rating: "DefenseHubStat4",
  overall_pm: "DefenseHubStat5",
  threep_dfg_pct: "DefenseHubStat6",
  twop_dfg_pct: "DefenseHubStat7",
  fifteenf_dfg_pct: "DefenseHubStat8",
  def_rim_pct: "DefenseHubStat9"
}.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", league: League::NBA, client: CLIENT) ⇒ Collection

Retrieves defense hub statistics for a stat category

Examples:

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

Parameters:

  • stat_category (Symbol)

    the stat category (:dreb, :stl, :blk, 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)

  • 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 defense hub stats



40
41
42
43
44
45
46
47
48
49
# File 'lib/nba/defense_hub.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",
  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, league_id: league_id}
  response = client.get(build_path(opts))
  parse_response(response, result_set, stat_category)
end