Class: SportsDataApi::Nhl::Season

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Season



6
7
8
9
10
11
# 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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/sports_data_api/nhl/season.rb', line 4

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/sports_data_api/nhl/season.rb', line 4

def type
  @type
end

#yearObject (readonly)

Returns the value of attribute year.



4
5
6
# File 'lib/sports_data_api/nhl/season.rb', line 4

def year
  @year
end

Class Method Details

.valid?(season) ⇒ Boolean

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

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



24
25
26
# File 'lib/sports_data_api/nhl/season.rb', line 24

def self.valid?(season)
  i[PRE REG PST].include?(season)
end

Instance Method Details

#gamesObject



13
14
15
16
17
# 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