Class: SportsDataApi::Mlb::Games
- Inherits:
-
Object
- Object
- SportsDataApi::Mlb::Games
- Includes:
- Enumerable
- Defined in:
- lib/sports_data_api/mlb/games.rb
Instance Attribute Summary collapse
-
#games ⇒ Object
readonly
Returns the value of attribute games.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(xml) ⇒ Games
constructor
A new instance of Games.
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
#games ⇒ Object (readonly)
Returns the value of attribute games.
5 6 7 |
# File 'lib/sports_data_api/mlb/games.rb', line 5 def games @games end |
#year ⇒ Object (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 |