Class: ErgastF1::Season

Inherits:
Object
  • Object
show all
Defined in:
lib/ergast_f1/season.rb

Instance Method Summary collapse

Constructor Details

#initialize(year = nil) ⇒ Season



3
4
5
# File 'lib/ergast_f1/season.rb', line 3

def initialize(year=nil)
  @year = year || Time.now.year
end

Instance Method Details

#constructor_standingsObject



23
24
25
26
27
# File 'lib/ergast_f1/season.rb', line 23

def constructor_standings
  parsed_response = ErgastClient.new("#{@year}/constructorStandings").api_get_request
  # Uh oh, array for standings lists
  parsed_response.dig("MRData", "StandingsTable", "StandingsLists").first["ConstructorStandings"]
end

#driver_standingsObject



17
18
19
20
21
# File 'lib/ergast_f1/season.rb', line 17

def driver_standings
  parsed_response = ErgastClient.new("#{@year}/driverStandings").api_get_request
  # Uh oh, array for standings lists
  parsed_response.dig("MRData", "StandingsTable", "StandingsLists").first["DriverStandings"]
end

#races(round = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/ergast_f1/season.rb', line 7

def races(round=nil)
  season_data = get_season

  if round
    season_data.dig("MRData", "RaceTable", "Races").select{|r| r["round"] == round.to_s}.first || (raise ApiError, "Nonexistent Round Number Specified")
  else
    season_data.dig("MRData", "RaceTable", "Races")
  end
end