Class: SportsDataApi::Nhl::Season
- Inherits:
-
Object
- Object
- SportsDataApi::Nhl::Season
- Defined in:
- lib/sports_data_api/nhl/season.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Class Method Summary collapse
-
.valid?(season) ⇒ Boolean
Check if the requested season is a valid NHL season type.
Instance Method Summary collapse
- #games ⇒ Object
-
#initialize(json) ⇒ Season
constructor
A new instance of Season.
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/sports_data_api/nhl/season.rb', line 4 def id @id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/sports_data_api/nhl/season.rb', line 4 def type @type end |
#year ⇒ Object (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
#games ⇒ Object
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 |