Class: MLB::Venues

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

Overview

Collection of venues from the MLB Stats API

Class Method Summary collapse

Class Method Details

.all(season: nil, sport: Utils::DEFAULT_SPORT_ID) ⇒ Array<Venue>

Retrieves all venues

Examples:

MLB::Venues.all

Parameters:

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

    the season year (defaults to current year)

  • sport (Integer, Sport) (defaults to: Utils::DEFAULT_SPORT_ID)

    the sport ID or Sport object

Returns:

  • (Array<Venue>)

    list of all venues



17
18
19
20
21
22
# File 'lib/mlb/venues.rb', line 17

def self.all(season: nil, sport: Utils::DEFAULT_SPORT_ID)
  season ||= Utils.current_season
  params = {sportId: Utils.extract_id(sport), season:}
  response = CLIENT.get("venues?#{Utils.build_query(params)}")
  from_json(response).venues
end

.find(venue, season: nil, sport: Utils::DEFAULT_SPORT_ID) ⇒ Venue?

Finds a venue by ID

Examples:

MLB::Venues.find(15)

Parameters:

  • venue (Integer, Venue)

    the venue ID or Venue object

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

    the season year (defaults to current year)

  • sport (Integer, Sport) (defaults to: Utils::DEFAULT_SPORT_ID)

    the sport ID or Sport object

Returns:

  • (Venue, nil)

    the venue if found



33
34
35
36
37
38
# File 'lib/mlb/venues.rb', line 33

def self.find(venue, season: nil, sport: Utils::DEFAULT_SPORT_ID)
  season ||= Utils.current_season
  params = {sportId: Utils.extract_id(sport), season:}
  response = CLIENT.get("venues/#{Utils.extract_id(venue)}?#{Utils.build_query(params)}")
  from_json(response).venues.first
end