Class: MLB::TeamStats

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

Overview

Provides methods for fetching team stats from the API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#statsArray<TeamStatGroup>

Returns the stat groups

Examples:

team_stats.stats #=> [#<MLB::TeamStatGroup>, ...]

Returns:



28
# File 'lib/mlb/team_stats.rb', line 28

attribute :stats, TeamStatGroup, collection: true

Class Method Details

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

Retrieves team stats

Examples:

Get team hitting stats

MLB::TeamStats.find(season: 2024, group: "hitting")

Get team pitching stats

MLB::TeamStats.find(season: 2024, group: "pitching", stats: "season")

Parameters:

  • 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:



45
46
47
48
49
50
# File 'lib/mlb/team_stats.rb', line 45

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