Class: MLB::Streaks

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

Overview

Provides methods for fetching streak data from the API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#streak_statsArray<StreakCategory>

Returns the streak categories

Examples:

streaks.streak_stats #=> [#<MLB::StreakCategory>, ...]

Returns:

  • the streak categories

API:

  • public



138
# File 'lib/mlb/streaks.rb', line 138

attribute :streak_stats, StreakCategory, collection: true

Class Method Details

.find(streak_type:, season: nil, limit: 10) ⇒ Array<PlayerStreak>

Retrieves streaks by type

Examples:

Get hitting streaks

MLB::Streaks.find(streak_type: "hittingStreak", season: 2024)

Parameters:

  • the streak type

  • (defaults to: nil)

    the season year (defaults to current year)

  • (defaults to: 10)

    the maximum number of results (defaults to 10)

Returns:

  • the streaks

API:

  • public



177
178
179
180
181
182
# File 'lib/mlb/streaks.rb', line 177

def self.find(streak_type:, season: nil, limit: 10)
  season ||= Utils.current_season
  params = {streakType: streak_type, season:, limit:}
  response = CLIENT.get("stats/streaks?#{Utils.build_query(params)}")
  from_json(response).streak_stats.first&.streaks || []
end

.hitting(season: nil, limit: 10) ⇒ Array<PlayerStreak>

Retrieves hitting streaks

Examples:

Get current hitting streaks

MLB::Streaks.hitting(season: 2024)

Parameters:

  • (defaults to: nil)

    the season year (defaults to current year)

  • (defaults to: 10)

    the maximum number of results (defaults to 10)

Returns:

  • the hitting streaks

API:

  • public



152
153
154
# File 'lib/mlb/streaks.rb', line 152

def self.hitting(season: nil, limit: 10)
  find(streak_type: "hittingStreak", season:, limit:)
end

.on_base(season: nil, limit: 10) ⇒ Array<PlayerStreak>

Retrieves on-base streaks

Examples:

Get current on-base streaks

MLB::Streaks.on_base(season: 2024)

Parameters:

  • (defaults to: nil)

    the season year (defaults to current year)

  • (defaults to: 10)

    the maximum number of results (defaults to 10)

Returns:

  • the on-base streaks

API:

  • public



164
165
166
# File 'lib/mlb/streaks.rb', line 164

def self.on_base(season: nil, limit: 10)
  find(streak_type: "onBaseStreak", season:, limit:)
end