Class: Inning

Inherits:
Object
  • Object
show all
Defined in:
lib/inning.rb

Overview

This class represents a single inning of an MLB game

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#away_teamObject

Returns the value of attribute away_team.



8
9
10
# File 'lib/inning.rb', line 8

def away_team
  @away_team
end

#bottom_atbatsObject

Returns the value of attribute bottom_atbats.



8
9
10
# File 'lib/inning.rb', line 8

def bottom_atbats
  @bottom_atbats
end

#gidObject

Returns the value of attribute gid.



8
9
10
# File 'lib/inning.rb', line 8

def gid
  @gid
end

#home_teamObject

Returns the value of attribute home_team.



8
9
10
# File 'lib/inning.rb', line 8

def home_team
  @home_team
end

#numObject

Returns the value of attribute num.



8
9
10
# File 'lib/inning.rb', line 8

def num
  @num
end

#top_atbatsObject

Returns the value of attribute top_atbats.



8
9
10
# File 'lib/inning.rb', line 8

def top_atbats
  @top_atbats
end

Instance Method Details

#load_from_id(gid, inning) ⇒ Object

loads an Inning object given a game id and an inning number



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/inning.rb', line 12

def load_from_id(gid, inning)
  @top_atbats = []
  @bottom_atbats = []
  @gid = gid
  begin
    @xml_data = GamedayFetcher.fetch_inningx(gid, inning)
    @xml_doc = REXML::Document.new(@xml_data)
    if @xml_doc.root
      @num = @xml_doc.root.attributes["num"]
      @away_team = @xml_doc.root.attributes["away_team"]
      @home_team = @xml_doc.root.attributes["home_team"]
      set_top_ab
      set_bottom_ab
    end
  rescue
    puts "Could not load inning file for #{gid}, inning #{inning.to_s}"
  end
end