Class: MLB::Sports

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

Overview

Collection of sports from the MLB Stats API

Class Method Summary collapse

Class Method Details

.allArray<Sport>

Retrieves all sports

Examples:

MLB::Sports.all

Returns:

  • (Array<Sport>)

    list of all sports



15
16
17
18
# File 'lib/mlb/sports.rb', line 15

def self.all
  response = CLIENT.get("sports")
  from_json(response).sports.sort
end

.find(sport) ⇒ Sport?

Finds a sport by ID

Examples:

MLB::Sports.find(1)

Parameters:

  • sport (Integer, Sport)

    the sport ID or Sport object

Returns:

  • (Sport, nil)

    the sport if found



27
28
29
30
# File 'lib/mlb/sports.rb', line 27

def self.find(sport)
  response = CLIENT.get("sports/#{Utils.extract_id(sport)}")
  from_json(response).sports.min_by { |s| s.sort_order || 0 }
end