Class: SportsDataApi::Mlb::Games

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sports_data_api/mlb/games.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Games



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

def initialize(xml)
  xml = xml.first if xml.is_a? Nokogiri::XML::NodeSet
  @year = xml['season_year']
  @games = []
  if xml.is_a? Nokogiri::XML::Element
    xml.xpath('event').each do |event|
      @games << Game.new(year: @year, xml: event)
    end
  end
end

Instance Attribute Details

#gamesObject (readonly)

Returns the value of attribute games.



5
6
7
# File 'lib/sports_data_api/mlb/games.rb', line 5

def games
  @games
end

#yearObject (readonly)

Returns the value of attribute year.



5
6
7
# File 'lib/sports_data_api/mlb/games.rb', line 5

def year
  @year
end

Instance Method Details

#each(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/sports_data_api/mlb/games.rb', line 18

def each &block
  @games.each do |game|
    if block_given?
      block.call game
    else
      yield game
    end
  end
end