class SportsDataApi::Nhl::Season

Attributes

id[R]
json[R]
type[R]
year[R]

Public Class Methods

new(json) click to toggle source
# File lib/sports_data_api/nhl/season.rb, line 6
def initialize(json)
  @json = json
  @id = json['season']['id']
  @year = json['season']['year']
  @type = json['season']['type'].to_sym
end
valid?(season) click to toggle source

Check if the requested season is a valid NHL season type.

The only valid types are: :pre, :reg, :pst

# File lib/sports_data_api/nhl/season.rb, line 24
def self.valid?(season)
  %i[PRE REG PST].include?(season)
end

Public Instance Methods

games() click to toggle source
# File lib/sports_data_api/nhl/season.rb, line 13
def games
  @games ||= json.fetch('games', []).map do |game_json|
    Game.new(year: year, season: type, json: game_json)
  end
end