Class: MLB::Standings
- Inherits:
-
Shale::Mapper
- Object
- Shale::Mapper
- MLB::Standings
- Defined in:
- lib/mlb/standings.rb
Overview
Provides methods for fetching standings from the API
Constant Summary collapse
- DEFAULT_LEAGUE_IDS =
Default league IDs for American League (103) and National League (104)
[103, 104].freeze
Class Method Summary collapse
-
.all(season: nil, league_ids: DEFAULT_LEAGUE_IDS) ⇒ Array<StandingsRecord>
Retrieves standings for the given leagues.
-
.find(division:, season: nil, league_ids: DEFAULT_LEAGUE_IDS) ⇒ StandingsRecord?
Retrieves standings for a specific division.
Class Method Details
.all(season: nil, league_ids: DEFAULT_LEAGUE_IDS) ⇒ Array<StandingsRecord>
Retrieves standings for the given leagues
26 27 28 29 30 31 |
# File 'lib/mlb/standings.rb', line 26 def self.all(season: nil, league_ids: DEFAULT_LEAGUE_IDS) season ||= Utils.current_season params = {leagueId: league_ids.join(","), season:} response = CLIENT.get("standings?#{Utils.build_query(params)}") from_json(response).records end |
.find(division:, season: nil, league_ids: DEFAULT_LEAGUE_IDS) ⇒ StandingsRecord?
Retrieves standings for a specific division
42 43 44 45 |
# File 'lib/mlb/standings.rb', line 42 def self.find(division:, season: nil, league_ids: DEFAULT_LEAGUE_IDS) division_id = Utils.extract_id(division) all(season:, league_ids:).find { |record| record.division&.id.eql?(division_id) } end |