Class: MLB::SingleTeamStats

Inherits:
Shale::Mapper
  • Object
show all
Defined in:
lib/mlb/single_team_stats.rb

Overview

Provides methods for fetching individual team stats from the API

Class Method Summary collapse

Class Method Details

.find(team:, season: nil, group: "hitting", stats: "season") ⇒ Array<TeamStat>

Retrieves stats for a specific team

Examples:

Get team hitting stats

MLB::SingleTeamStats.find(team: 147, season: 2024, group: "hitting")

Get team pitching stats

MLB::SingleTeamStats.find(team: Team.new(id: 147), season: 2024, group: "pitching")

Parameters:

  • team (Integer, Team)

    the team ID or Team object

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

    the season year (defaults to current year)

  • group (String) (defaults to: "hitting")

    the stat group (hitting, pitching, fielding)

  • stats (String) (defaults to: "season")

    the stats type (default: season)

Returns:



25
26
27
28
29
30
31
# File 'lib/mlb/single_team_stats.rb', line 25

def self.find(team:, season: nil, group: "hitting", stats: "season")
  season ||= Utils.current_season
  team_id = Utils.extract_id(team)
  params = {season:, group:, stats:}
  response = CLIENT.get("teams/#{team_id}/stats?#{Utils.build_query(params)}")
  from_json(response).stats.first&.splits || []
end