Class: Players

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#gidObject

Returns the value of attribute gid.



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

def gid
  @gid
end

#rostersObject

Returns the value of attribute rosters.



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

def rosters
  @rosters
end

#umpiresObject

Returns the value of attribute umpires.



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

def umpires
  @umpires
end

#venueObject

Returns the value of attribute venue.



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

def venue
  @venue
end

#xml_dataObject

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_rostersObject



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_umpiresObject



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