Class: Players
- Inherits:
-
Object
- Object
- Players
- Defined in:
- lib/players.rb
Overview
This class represents the players.xml file found on the gameday server for each MLB game.
The players.xml file contains a listing of all players on the home and away teams for the specified game
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#gid ⇒ Object
Returns the value of attribute gid.
-
#rosters ⇒ Object
Returns the value of attribute rosters.
-
#umpires ⇒ Object
Returns the value of attribute umpires.
-
#venue ⇒ Object
Returns the value of attribute venue.
-
#xml_data ⇒ Object
Returns the value of attribute xml_data.
Instance Method Summary collapse
-
#load_from_id(gid) ⇒ Object
Loads the players XML from the MLB gameday server and parses it using REXML.
- #set_rosters ⇒ Object
- #set_umpires ⇒ Object
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
8 9 10 |
# File 'lib/players.rb', line 8 def date @date end |
#gid ⇒ Object
Returns the value of attribute gid.
8 9 10 |
# File 'lib/players.rb', line 8 def gid @gid end |
#rosters ⇒ Object
Returns the value of attribute rosters.
8 9 10 |
# File 'lib/players.rb', line 8 def rosters @rosters end |
#umpires ⇒ Object
Returns the value of attribute umpires.
8 9 10 |
# File 'lib/players.rb', line 8 def umpires @umpires end |
#venue ⇒ Object
Returns the value of attribute venue.
8 9 10 |
# File 'lib/players.rb', line 8 def venue @venue end |
#xml_data ⇒ Object
Returns the value of attribute xml_data.
8 9 10 |
# File 'lib/players.rb', line 8 def xml_data @xml_data end |
Instance Method Details
#load_from_id(gid) ⇒ Object
Loads the players XML from the MLB gameday server and parses it using REXML
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/players.rb', line 11 def load_from_id(gid) @gid = gid @rosters = [] @umpires = {} @xml_data = GamedayFetcher.fetch_players(gid) @xml_doc = REXML::Document.new(@xml_data) if @xml_doc.root self.set_rosters self.set_umpires end end |
#set_rosters ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/players.rb', line 24 def set_rosters() away_roster = Roster.new away_roster.init(@xml_doc.root.elements["team[@type='away']"], self.gid) self.rosters << away_roster home_roster = Roster.new home_roster.init(@xml_doc.root.elements["team[@type='home']"], self.gid) @rosters << home_roster end |
#set_umpires ⇒ Object
34 35 36 37 38 39 |
# File 'lib/players.rb', line 34 def set_umpires() @umpires['home'] = @xml_doc.root.elements["umpires/umpire[@position='home']"].attributes["name"] @umpires['first'] = @xml_doc.root.elements["umpires/umpire[@position='first']"].attributes["name"] @umpires['second'] = @xml_doc.root.elements["umpires/umpire[@position='second']"].attributes["name"] @umpires['third'] = @xml_doc.root.elements["umpires/umpire[@position='third']"].attributes["name"] end |