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(xml) ⇒ Season

Returns a new instance of Season.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/sports_data_api/nhl/season.rb', line 6

def initialize(xml)
  if xml.is_a? Nokogiri::XML::NodeSet
    @id = xml.first["id"]
    @year = xml.first["year"].to_i
    @type = xml.first["type"].to_sym

    @games = xml.first.xpath("games/game").map do |game_xml|
      Game.new(year: @year, season: @type, xml: game_xml)
    end
  end
end

Instance Attribute Details

#gamesObject (readonly)

Returns the value of attribute games.



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

def games
  @games
end

#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

Returns:

  • (Boolean)


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

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