class ErgastF1::Season

Public Class Methods

new(year=nil) click to toggle source
# File lib/ergast_f1/season.rb, line 3
def initialize(year=nil)
  @year = year || Time.now.year
end

Public Instance Methods

constructor_standings() click to toggle source
# 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_standings() click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

get_season() click to toggle source
# File lib/ergast_f1/season.rb, line 31
def get_season
  ErgastClient.new("#{@year}").api_get_request
end