Class: Game
- Inherits:
-
Object
- Object
- Game
- Defined in:
- lib/game.rb
Overview
This class represents a single MLB game
Instance Attribute Summary collapse
-
#ampm ⇒ Object
additional attributes from master_scoreboard.xml.
-
#away_code ⇒ Object
Returns the value of attribute away_code.
-
#away_division ⇒ Object
Returns the value of attribute away_division.
-
#away_errors ⇒ Object
Returns the value of attribute away_errors.
-
#away_file_code ⇒ Object
Returns the value of attribute away_file_code.
-
#away_games_back ⇒ Object
Returns the value of attribute away_games_back.
-
#away_games_back_wildcard ⇒ Object
Returns the value of attribute away_games_back_wildcard.
-
#away_hits ⇒ Object
Returns the value of attribute away_hits.
-
#away_innings ⇒ Object
An arry of one element for each inning, the element is the home or away score.
-
#away_loss ⇒ Object
Returns the value of attribute away_loss.
-
#away_name_abbrev ⇒ Object
Returns the value of attribute away_name_abbrev.
-
#away_runs ⇒ Object
Returns the value of attribute away_runs.
-
#away_team_city ⇒ Object
Returns the value of attribute away_team_city.
-
#away_team_id ⇒ Object
Returns the value of attribute away_team_id.
-
#away_team_name ⇒ Object
Returns the value of attribute away_team_name.
-
#away_win ⇒ Object
Returns the value of attribute away_win.
-
#boxscore ⇒ Object
Returns the value of attribute boxscore.
-
#date ⇒ Object
Returns the value of attribute date.
-
#day ⇒ Object
Returns the value of attribute day.
-
#eventlog ⇒ Object
Returns the value of attribute eventlog.
-
#game_number ⇒ Object
Returns the value of attribute game_number.
-
#game_pk ⇒ Object
additional attributes from master_scoreboard.xml.
-
#game_type ⇒ Object
additional attributes from master_scoreboard.xml.
-
#gameday ⇒ Object
Returns the value of attribute gameday.
-
#gameday_sw ⇒ Object
Returns the value of attribute gameday_sw.
-
#gid ⇒ Object
Returns the value of attribute gid.
-
#home_code ⇒ Object
Returns the value of attribute home_code.
-
#home_division ⇒ Object
Returns the value of attribute home_division.
-
#home_errors ⇒ Object
Returns the value of attribute home_errors.
-
#home_file_code ⇒ Object
Returns the value of attribute home_file_code.
-
#home_games_back ⇒ Object
Returns the value of attribute home_games_back.
-
#home_games_back_wildcard ⇒ Object
Returns the value of attribute home_games_back_wildcard.
-
#home_hits ⇒ Object
Returns the value of attribute home_hits.
-
#home_innings ⇒ Object
An arry of one element for each inning, the element is the home or away score.
-
#home_loss ⇒ Object
Returns the value of attribute home_loss.
-
#home_name_abbrev ⇒ Object
Returns the value of attribute home_name_abbrev.
-
#home_runs ⇒ Object
Returns the value of attribute home_runs.
-
#home_team ⇒ Object
Returns the value of attribute home_team.
-
#home_team_abbrev ⇒ Object
Returns the value of attribute home_team_abbrev.
-
#home_team_city ⇒ Object
Returns the value of attribute home_team_city.
-
#home_team_id ⇒ Object
Returns the value of attribute home_team_id.
-
#home_team_name ⇒ Object
Returns the value of attribute home_team_name.
-
#home_win ⇒ Object
Returns the value of attribute home_win.
-
#homeruns ⇒ Object
an array of players with homeruns in the game.
-
#innings ⇒ Object
array of Inning objects, from innings files.
-
#league ⇒ Object
Returns the value of attribute league.
-
#losing_pitcher ⇒ Object
Instances of Player object.
-
#media ⇒ Object
Returns the value of attribute media.
-
#month ⇒ Object
Returns the value of attribute month.
-
#players ⇒ Object
data from the players.xml file.
-
#rosters ⇒ Object
Returns the value of attribute rosters.
-
#save_pitcher ⇒ Object
Instances of Player object.
-
#scoreboard_game_id ⇒ Object
additional attributes from master_scoreboard.xml.
-
#status ⇒ Object
An instance of GameStatus object.
-
#time ⇒ Object
additional attributes from master_scoreboard.xml.
-
#time_zone ⇒ Object
additional attributes from master_scoreboard.xml.
-
#venue ⇒ Object
additional attributes from master_scoreboard.xml.
-
#venue_w_chan_loc ⇒ Object
Returns the value of attribute venue_w_chan_loc.
-
#visit_team_abbrev ⇒ Object
Returns the value of attribute visit_team_abbrev.
-
#visit_team_name ⇒ Object
Returns the value of attribute visit_team_name.
-
#visiting_team ⇒ Object
Returns the value of attribute visiting_team.
-
#winning_pitcher ⇒ Object
Instances of Player object.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
-
.find_by_date(year, month, day) ⇒ Object
Returns an array of Game objects for each game for the specified day.
- .find_by_month(year, month) ⇒ Object
Instance Method Summary collapse
-
#dump_boxscore ⇒ Object
Saves an HTML version of the boxscore for the game.
-
#get_atbats ⇒ Object
Returns an array of AtBat objects that represent each atbat of the game.
-
#get_attendance ⇒ Object
Returns a string holding the game attendance value.
- #get_away_runs ⇒ Object
-
#get_batters(home_or_away) ⇒ Object
Returns an array of either home or away batters for this game home_or_away must be a string with value ‘home’ or ‘away’ The values in the returned array are BattingAppearance instances.
-
#get_boxscore ⇒ Object
Returns a BoxScore object representing the boxscore for this game.
-
#get_closing_pitchers ⇒ Object
Returns an array of the closing pitchers for the game [0] = visiting team pitcher [1] = home team pitcher.
- #get_date ⇒ Object
- #get_eventlog ⇒ Object
- #get_hitchart ⇒ Object
- #get_home_runs ⇒ Object
-
#get_innings ⇒ Object
Returns an array of Inning objects that represent each inning of the game.
- #get_lineups ⇒ Object
- #get_media ⇒ Object
-
#get_num_innings ⇒ Object
Returns the number of innings for this game.
-
#get_pitchers(home_or_away) ⇒ Object
Returns an array of all pitchers for either the home team or the away team.
-
#get_pitches(pid) ⇒ Object
Returns an array of pitches from this game for the pitcher identified by pid.
- #get_pitching ⇒ Object
-
#get_rosters ⇒ Object
Returns a 2 element array containing the home and visiting rosters for this game [0] array of all visitor players [1] array of all home players.
-
#get_score ⇒ Object
Returns a 2 element array holding the game score [0] visiting team runs [1] home team runs.
-
#get_starting_pitchers ⇒ Object
Returns an array of the starting pitchers for the game [0] = visiting team pitcher [1] = home team pitcher.
- #get_temp ⇒ Object
-
#get_umpires ⇒ Object
Returns a hash of umpires for this game.
- #get_wind_dir ⇒ Object
- #get_wind_speed ⇒ Object
-
#get_winner ⇒ Object
Returns the team abreviation of the winning team.
-
#initialize(gid) ⇒ Game
constructor
A new instance of Game.
-
#load_from_scoreboard(element) ⇒ Object
Setup a Game object from data read from the master_scoreboard.xml file.
-
#print_linescore ⇒ Object
Returns a string containing the linescore in the following printed format: Away 1 3 1 Home 5 8 0.
-
#set_homeruns(element) ⇒ Object
Sets a list of players who had homeruns in this game from data in the master_scoreboard.xml file.
-
#set_innings(element) ⇒ Object
Sets the away and home innings array containing scores by inning from data in the master_scoreboard.xml file.
-
#set_pitchers(element) ⇒ Object
Sets the pitchers of record (win, lose, save) from data in the master_scoreboard.xml file.
-
#set_status(element) ⇒ Object
Sets the game status from data in the master_scoreboard.xml file.
-
#set_totals(element) ⇒ Object
Sets the Runs/Hits/Errors totals from data in the master_scoreboard.xml file.
Constructor Details
#initialize(gid) ⇒ Game
Returns a new instance of Game.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/game.rb', line 36 def initialize(gid) @innings = [] team = Team.new('') if gid @gid = gid @xml_data = GamedayFetcher.fetch_game_xml(gid) if @xml_data && @xml_data.size > 0 @xml_doc = REXML::Document.new(@xml_data) @game_type = @xml_doc.root.attributes["type"] @time = @xml_doc.root.attributes["local_game_time"] info = GamedayUtil.parse_gameday_id('gid_'+gid) @home_team_abbrev = info["home_team_abbrev"] @visit_team_abbrev = info["visiting_team_abbrev"] @visiting_team = Team.new(@visit_team_abbrev ) @home_team = Team.new(@home_team_abbrev ) @year = info["year"] @month = info["month"] @day = info["day"] @game_number = info["game_number"] if Team.teams[@home_team_abbrev] @home_team_name = Team.teams[@home_team_abbrev][0] else @home_team_name = @home_team_abbrev end if Team.teams[@visit_team_abbrev] @visit_team_name = Team.teams[@visit_team_abbrev][0] else @visit_team_name = @visit_team_abbrev end else raise ArgumentError, "Could not find game.xml" end end end |
Instance Attribute Details
#ampm ⇒ Object
additional attributes from master_scoreboard.xml
23 24 25 |
# File 'lib/game.rb', line 23 def ampm @ampm end |
#away_code ⇒ Object
Returns the value of attribute away_code.
24 25 26 |
# File 'lib/game.rb', line 24 def away_code @away_code end |
#away_division ⇒ Object
Returns the value of attribute away_division.
25 26 27 |
# File 'lib/game.rb', line 25 def away_division @away_division end |
#away_errors ⇒ Object
Returns the value of attribute away_errors.
34 35 36 |
# File 'lib/game.rb', line 34 def away_errors @away_errors end |
#away_file_code ⇒ Object
Returns the value of attribute away_file_code.
24 25 26 |
# File 'lib/game.rb', line 24 def away_file_code @away_file_code end |
#away_games_back ⇒ Object
Returns the value of attribute away_games_back.
27 28 29 |
# File 'lib/game.rb', line 27 def away_games_back @away_games_back end |
#away_games_back_wildcard ⇒ Object
Returns the value of attribute away_games_back_wildcard.
27 28 29 |
# File 'lib/game.rb', line 27 def away_games_back_wildcard @away_games_back_wildcard end |
#away_hits ⇒ Object
Returns the value of attribute away_hits.
34 35 36 |
# File 'lib/game.rb', line 34 def away_hits @away_hits end |
#away_innings ⇒ Object
An arry of one element for each inning, the element is the home or away score
33 34 35 |
# File 'lib/game.rb', line 33 def away_innings @away_innings end |
#away_loss ⇒ Object
Returns the value of attribute away_loss.
28 29 30 |
# File 'lib/game.rb', line 28 def away_loss @away_loss end |
#away_name_abbrev ⇒ Object
Returns the value of attribute away_name_abbrev.
24 25 26 |
# File 'lib/game.rb', line 24 def away_name_abbrev @away_name_abbrev end |
#away_runs ⇒ Object
Returns the value of attribute away_runs.
34 35 36 |
# File 'lib/game.rb', line 34 def away_runs @away_runs end |
#away_team_city ⇒ Object
Returns the value of attribute away_team_city.
25 26 27 |
# File 'lib/game.rb', line 25 def away_team_city @away_team_city end |
#away_team_id ⇒ Object
Returns the value of attribute away_team_id.
24 25 26 |
# File 'lib/game.rb', line 24 def away_team_id @away_team_id end |
#away_team_name ⇒ Object
Returns the value of attribute away_team_name.
25 26 27 |
# File 'lib/game.rb', line 25 def away_team_name @away_team_name end |
#away_win ⇒ Object
Returns the value of attribute away_win.
28 29 30 |
# File 'lib/game.rb', line 28 def away_win @away_win end |
#boxscore ⇒ Object
Returns the value of attribute boxscore.
16 17 18 |
# File 'lib/game.rb', line 16 def boxscore @boxscore end |
#date ⇒ Object
Returns the value of attribute date.
16 17 18 |
# File 'lib/game.rb', line 16 def date @date end |
#day ⇒ Object
Returns the value of attribute day.
14 15 16 |
# File 'lib/game.rb', line 14 def day @day end |
#eventlog ⇒ Object
Returns the value of attribute eventlog.
16 17 18 |
# File 'lib/game.rb', line 16 def eventlog @eventlog end |
#game_number ⇒ Object
Returns the value of attribute game_number.
14 15 16 |
# File 'lib/game.rb', line 14 def game_number @game_number end |
#game_pk ⇒ Object
additional attributes from master_scoreboard.xml
23 24 25 |
# File 'lib/game.rb', line 23 def game_pk @game_pk end |
#game_type ⇒ Object
additional attributes from master_scoreboard.xml
23 24 25 |
# File 'lib/game.rb', line 23 def game_type @game_type end |
#gameday ⇒ Object
Returns the value of attribute gameday.
28 29 30 |
# File 'lib/game.rb', line 28 def gameday @gameday end |
#gameday_sw ⇒ Object
Returns the value of attribute gameday_sw.
27 28 29 |
# File 'lib/game.rb', line 27 def gameday_sw @gameday_sw end |
#gid ⇒ Object
Returns the value of attribute gid.
14 15 16 |
# File 'lib/game.rb', line 14 def gid @gid end |
#home_code ⇒ Object
Returns the value of attribute home_code.
26 27 28 |
# File 'lib/game.rb', line 26 def home_code @home_code end |
#home_division ⇒ Object
Returns the value of attribute home_division.
26 27 28 |
# File 'lib/game.rb', line 26 def home_division @home_division end |
#home_errors ⇒ Object
Returns the value of attribute home_errors.
34 35 36 |
# File 'lib/game.rb', line 34 def home_errors @home_errors end |
#home_file_code ⇒ Object
Returns the value of attribute home_file_code.
26 27 28 |
# File 'lib/game.rb', line 26 def home_file_code @home_file_code end |
#home_games_back ⇒ Object
Returns the value of attribute home_games_back.
27 28 29 |
# File 'lib/game.rb', line 27 def home_games_back @home_games_back end |
#home_games_back_wildcard ⇒ Object
Returns the value of attribute home_games_back_wildcard.
27 28 29 |
# File 'lib/game.rb', line 27 def home_games_back_wildcard @home_games_back_wildcard end |
#home_hits ⇒ Object
Returns the value of attribute home_hits.
34 35 36 |
# File 'lib/game.rb', line 34 def home_hits @home_hits end |
#home_innings ⇒ Object
An arry of one element for each inning, the element is the home or away score
33 34 35 |
# File 'lib/game.rb', line 33 def home_innings @home_innings end |
#home_loss ⇒ Object
Returns the value of attribute home_loss.
28 29 30 |
# File 'lib/game.rb', line 28 def home_loss @home_loss end |
#home_name_abbrev ⇒ Object
Returns the value of attribute home_name_abbrev.
24 25 26 |
# File 'lib/game.rb', line 24 def home_name_abbrev @home_name_abbrev end |
#home_runs ⇒ Object
Returns the value of attribute home_runs.
34 35 36 |
# File 'lib/game.rb', line 34 def home_runs @home_runs end |
#home_team ⇒ Object
Returns the value of attribute home_team.
14 15 16 |
# File 'lib/game.rb', line 14 def home_team @home_team end |
#home_team_abbrev ⇒ Object
Returns the value of attribute home_team_abbrev.
14 15 16 |
# File 'lib/game.rb', line 14 def home_team_abbrev @home_team_abbrev end |
#home_team_city ⇒ Object
Returns the value of attribute home_team_city.
26 27 28 |
# File 'lib/game.rb', line 26 def home_team_city @home_team_city end |
#home_team_id ⇒ Object
Returns the value of attribute home_team_id.
26 27 28 |
# File 'lib/game.rb', line 26 def home_team_id @home_team_id end |
#home_team_name ⇒ Object
Returns the value of attribute home_team_name.
14 15 16 |
# File 'lib/game.rb', line 14 def home_team_name @home_team_name end |
#home_win ⇒ Object
Returns the value of attribute home_win.
28 29 30 |
# File 'lib/game.rb', line 28 def home_win @home_win end |
#homeruns ⇒ Object
an array of players with homeruns in the game
31 32 33 |
# File 'lib/game.rb', line 31 def homeruns @homeruns end |
#innings ⇒ Object
array of Inning objects, from innings files
18 19 20 |
# File 'lib/game.rb', line 18 def innings @innings end |
#league ⇒ Object
Returns the value of attribute league.
28 29 30 |
# File 'lib/game.rb', line 28 def league @league end |
#losing_pitcher ⇒ Object
Instances of Player object
32 33 34 |
# File 'lib/game.rb', line 32 def losing_pitcher @losing_pitcher end |
#media ⇒ Object
Returns the value of attribute media.
16 17 18 |
# File 'lib/game.rb', line 16 def media @media end |
#month ⇒ Object
Returns the value of attribute month.
14 15 16 |
# File 'lib/game.rb', line 14 def month @month end |
#players ⇒ Object
data from the players.xml file
20 21 22 |
# File 'lib/game.rb', line 20 def players @players end |
#rosters ⇒ Object
Returns the value of attribute rosters.
16 17 18 |
# File 'lib/game.rb', line 16 def rosters @rosters end |
#save_pitcher ⇒ Object
Instances of Player object
32 33 34 |
# File 'lib/game.rb', line 32 def save_pitcher @save_pitcher end |
#scoreboard_game_id ⇒ Object
additional attributes from master_scoreboard.xml
23 24 25 |
# File 'lib/game.rb', line 23 def scoreboard_game_id @scoreboard_game_id end |
#status ⇒ Object
An instance of GameStatus object
30 31 32 |
# File 'lib/game.rb', line 30 def status @status end |
#time ⇒ Object
additional attributes from master_scoreboard.xml
23 24 25 |
# File 'lib/game.rb', line 23 def time @time end |
#time_zone ⇒ Object
additional attributes from master_scoreboard.xml
23 24 25 |
# File 'lib/game.rb', line 23 def time_zone @time_zone end |
#venue ⇒ Object
additional attributes from master_scoreboard.xml
23 24 25 |
# File 'lib/game.rb', line 23 def venue @venue end |
#venue_w_chan_loc ⇒ Object
Returns the value of attribute venue_w_chan_loc.
28 29 30 |
# File 'lib/game.rb', line 28 def venue_w_chan_loc @venue_w_chan_loc end |
#visit_team_abbrev ⇒ Object
Returns the value of attribute visit_team_abbrev.
14 15 16 |
# File 'lib/game.rb', line 14 def visit_team_abbrev @visit_team_abbrev end |
#visit_team_name ⇒ Object
Returns the value of attribute visit_team_name.
14 15 16 |
# File 'lib/game.rb', line 14 def visit_team_name @visit_team_name end |
#visiting_team ⇒ Object
Returns the value of attribute visiting_team.
14 15 16 |
# File 'lib/game.rb', line 14 def visiting_team @visiting_team end |
#winning_pitcher ⇒ Object
Instances of Player object
32 33 34 |
# File 'lib/game.rb', line 32 def winning_pitcher @winning_pitcher end |
#year ⇒ Object
Returns the value of attribute year.
14 15 16 |
# File 'lib/game.rb', line 14 def year @year end |
Class Method Details
.find_by_date(year, month, day) ⇒ Object
Returns an array of Game objects for each game for the specified day
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/game.rb', line 207 def self.find_by_date(year, month, day) begin games = [] games_page = GamedayFetcher.fetch_games_page(year, month, day) if games_page @hp = Hpricot(games_page) a = @hp.at('ul') (a/"a").each do |link| # look at each link inside of a ul tag if link.inner_html.include?('gid') # if the link contains the text 'gid' then it is a listing of a game str = link.inner_html gid = str[5..str.length-2] begin game = Game.new(gid) games.push game rescue puts "Could not create game object for #{year}, #{month}, #{day} - #{gid}" end end end else puts "Could not read games page for #{year}, #{month}, #{day}." end return games rescue puts "No games data found for #{year}, #{month}, #{day}." end end |
.find_by_month(year, month) ⇒ Object
195 196 197 198 199 200 201 202 203 |
# File 'lib/game.rb', line 195 def self.find_by_month(year, month) games = [] start_date = Date.new(year.to_i, month.to_i) # first day of month end_date = (start_date >> 1)-1 # last day of month ((start_date)..(end_date)).each do |dt| games += find_by_date(year, month, dt.day.to_s) end games end |
Instance Method Details
#dump_boxscore ⇒ Object
Saves an HTML version of the boxscore for the game
272 273 274 275 276 277 278 279 |
# File 'lib/game.rb', line 272 def dump_boxscore if self.gid bs = get_boxscore GamedayUtil.save_file("boxscore.html", bs.to_html('boxscore.html.erb')) else puts "No data for input specified" end end |
#get_atbats ⇒ Object
Returns an array of AtBat objects that represent each atbat of the game
441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/game.rb', line 441 def get_atbats atbats = [] innings = get_innings innings.each do |inning| inning.top_atbats.each do |atbat| atbats << atbat end inning.bottom_atbats.each do |atbat| atbats << atbat end end atbats end |
#get_attendance ⇒ Object
Returns a string holding the game attendance value
410 411 412 413 414 |
# File 'lib/game.rb', line 410 def get_attendance game_info = get_boxscore.game_info # parse game_info to get attendance game_info[game_info.length-12..game_info.length-7] end |
#get_away_runs ⇒ Object
522 523 524 525 |
# File 'lib/game.rb', line 522 def get_away_runs bs = get_boxscore bs.away_runs end |
#get_batters(home_or_away) ⇒ Object
Returns an array of either home or away batters for this game home_or_away must be a string with value ‘home’ or ‘away’ The values in the returned array are BattingAppearance instances
352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/game.rb', line 352 def get_batters(home_or_away) if self.gid bs = get_boxscore if home_or_away == 'away' bs.batters[0] else bs.batters[1] end else puts "No data for input specified" end end |
#get_boxscore ⇒ Object
Returns a BoxScore object representing the boxscore for this game
261 262 263 264 265 266 267 268 |
# File 'lib/game.rb', line 261 def get_boxscore if !@boxscore box = BoxScore.new box.load_from_id(self.gid) @boxscore = box end @boxscore end |
#get_closing_pitchers ⇒ Object
Returns an array of the closing pitchers for the game
[0] = visiting team pitcher
[1] = home team pitcher
311 312 313 314 315 316 317 |
# File 'lib/game.rb', line 311 def get_closing_pitchers results = [] away_pitchers = get_pitchers('away') home_pitchers = get_pitchers('home') results << away_pitchers[(away_pitchers.size) - 1] results << home_pitchers[(home_pitchers.size) -1] end |
#get_date ⇒ Object
492 493 494 495 |
# File 'lib/game.rb', line 492 def get_date bs = get_boxscore bs.date end |
#get_eventlog ⇒ Object
251 252 253 254 255 256 257 |
# File 'lib/game.rb', line 251 def get_eventlog if !@eventlog @eventlog = EventLog.new @eventlog.load_from_id(@gid) end @eventlog end |
#get_hitchart ⇒ Object
456 457 458 459 460 461 462 |
# File 'lib/game.rb', line 456 def get_hitchart if !@hitchart @hitchart = Hitchart.new @hitchart.load_from_gid(@gid) end @hitchart end |
#get_home_runs ⇒ Object
516 517 518 519 |
# File 'lib/game.rb', line 516 def get_home_runs bs = get_boxscore bs.home_runs end |
#get_innings ⇒ Object
Returns an array of Inning objects that represent each inning of the game
427 428 429 430 431 432 433 434 435 436 437 |
# File 'lib/game.rb', line 427 def get_innings if @innings.length == 0 inn_count = get_num_innings (1..get_num_innings).each do |inn| inning = Inning.new inning.load_from_id(@gid, inn) @innings << inning end end @innings end |
#get_lineups ⇒ Object
369 370 371 372 373 |
# File 'lib/game.rb', line 369 def get_lineups results = [] results << get_batters('away') results << get_batters('home') end |
#get_media ⇒ Object
417 418 419 420 421 422 423 |
# File 'lib/game.rb', line 417 def get_media if !@media @media = Media.new @media.load_from_id(@gid) end @media end |
#get_num_innings ⇒ Object
Returns the number of innings for this game
466 467 468 469 470 471 472 473 |
# File 'lib/game.rb', line 466 def get_num_innings bs = get_boxscore if bs.linescore return get_boxscore.linescore.innings.length else return 0 end end |
#get_pitchers(home_or_away) ⇒ Object
Returns an array of all pitchers for either the home team or the away team. The values in the returned array are PitchingAppearance instances
322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/game.rb', line 322 def get_pitchers(home_or_away) if self.gid bs = get_boxscore if home_or_away == 'away' bs.pitchers[0] else bs.pitchers[1] end else puts "No data for input specified" end end |
#get_pitches(pid) ⇒ Object
Returns an array of pitches from this game for the pitcher identified by pid
337 338 339 340 341 342 343 344 345 346 |
# File 'lib/game.rb', line 337 def get_pitches(pid) results = [] atbats = get_atbats atbats.each do |ab| if ab.pitcher_id == pid results << ab.pitches end end results.flatten end |
#get_pitching ⇒ Object
379 380 381 382 383 |
# File 'lib/game.rb', line 379 def get_pitching results = [] results << get_pitchers('away') results << get_pitchers('home') end |
#get_rosters ⇒ Object
Returns a 2 element array containing the home and visiting rosters for this game
[0] array of all visitor players
[1] array of all home players
241 242 243 244 245 246 247 248 |
# File 'lib/game.rb', line 241 def get_rosters if !@rosters players = Players.new players.load_from_id(@gid) @rosters = players.rosters end @rosters end |
#get_score ⇒ Object
Returns a 2 element array holding the game score
[0] visiting team runs
[1] home team runs
400 401 402 403 404 405 406 |
# File 'lib/game.rb', line 400 def get_score results = [] ls = get_boxscore.linescore results << ls.away_team_runs results << ls.home_team_runs results end |
#get_starting_pitchers ⇒ Object
Returns an array of the starting pitchers for the game
[0] = visiting team pitcher
[1] = home team pitcher
301 302 303 304 305 |
# File 'lib/game.rb', line 301 def get_starting_pitchers results = [] results << get_pitchers('away')[0] results << get_pitchers('home')[0] end |
#get_temp ⇒ Object
498 499 500 501 |
# File 'lib/game.rb', line 498 def get_temp bs = get_boxscore bs.temp end |
#get_umpires ⇒ Object
Returns a hash of umpires for this game
{ 'hp' => 'john doe',
'1b' => 'paul jones',
'2b' => 'mike james',
'3b' => 'pete myers' }
483 484 485 486 487 488 489 |
# File 'lib/game.rb', line 483 def get_umpires if !@players @players = Players.new @players.load_from_id(@gid) end @players.umpires end |
#get_wind_dir ⇒ Object
510 511 512 513 |
# File 'lib/game.rb', line 510 def get_wind_dir bs = get_boxscore bs.wind_dir end |
#get_wind_speed ⇒ Object
504 505 506 507 |
# File 'lib/game.rb', line 504 def get_wind_speed bs = get_boxscore bs.wind_speed end |
#get_winner ⇒ Object
Returns the team abreviation of the winning team
387 388 389 390 391 392 393 394 |
# File 'lib/game.rb', line 387 def get_winner ls = get_boxscore.linescore if ls.home_team_runs > ls.away_team_runs return home_team_abbrev else return visit_team_abbrev end end |
#load_from_scoreboard(element) ⇒ Object
Setup a Game object from data read from the master_scoreboard.xml file
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/game.rb', line 73 def load_from_scoreboard(element) @away_innings = [] @home_innings = [] @scoreboard_game_id = element.attributes['id'] @ampm = element.attributes['ampm'] @venue = element.attributes['venue'] @game_pk = element.attributes['game_pk'] @time = element.attributes['time'] @time_zone = element.attributes['time_zone'] @game_type = element.attributes['game_type'] @away_name_abbrev = element.attributes['away_name_abbrev'] @home_name_abbrev = element.attributes['home_name_abbrev'] @away_code = element.attributes['away_code'] @away_file_code = element.attributes['away_file_code'] @away_team_id = element.attributes['away_team_id'] @away_team_city = element.attributes['away_team_city'] @away_team_name = element.attributes['away_team_name'] @away_division = element.attributes['away_division'] @home_code = element.attributes['home_code'] @home_file_code = element.attributes['home_file_code'] @home_team_id = element.attributes['home_team_id'] @home_team_city = element.attributes['home_team_city'] @home_team_name = element.attributes['home_team_name'] @home_division = element.attributes['home_division'] @day = element.attributes['day'] @gameday_sw = element.attributes['gameday_sw'] @away_games_back = element.attributes['away_games_back'] @home_games_back = element.attributes['home_games_back'] @away_games_back_wildcard = element.attributes['away_games_back_wildcard'] @home_games_back_wildcard = element.attributes['home_games_back_wildcard'] @venue_w_chan_loc = element.attributes['venue_w_chan_loc'] @gameday = element.attributes['gameday'] @away_win = element.attributes['away_win'] @away_loss = element.attributes['away_loss'] @home_win = element.attributes['home_win'] @home_loss = element.attributes['home_loss'] @league = element.attributes['league'] set_status(element) set_innings(element) set_totals(element) set_pitchers(element) set_homeruns(element) end |
#print_linescore ⇒ Object
Returns a string containing the linescore in the following printed format:
Away 1 3 1
Home 5 8 0
285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/game.rb', line 285 def print_linescore bs = get_boxscore output = '' if bs.linescore output += self.visit_team_name + ' ' + bs.linescore.away_team_runs + ' ' + bs.linescore.away_team_hits + ' ' + bs.linescore.away_team_errors + "\n" output += self.home_team_name + ' ' + bs.linescore.home_team_runs + ' ' + bs.linescore.home_team_hits + ' ' + bs.linescore.home_team_errors else output += 'No linescore available for ' + @visit_team_name + ' vs. ' + @home_team_name end output end |
#set_homeruns(element) ⇒ Object
Sets a list of players who had homeruns in this game from data in the master_scoreboard.xml file
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/game.rb', line 162 def set_homeruns(element) @homeruns = [] element.elements.each("home_runs/player") do |hr| player = Player.new player.last = hr.attributes['last'] player.first = hr.attributes['first'] player.hr = hr.attributes['hr'] player.std_hr = hr.attributes['std_hr'] player.team_code = hr.attributes['team_code'] @homeruns << player end end |
#set_innings(element) ⇒ Object
Sets the away and home innings array containing scores by inning from data in the master_scoreboard.xml file
136 137 138 139 140 141 |
# File 'lib/game.rb', line 136 def set_innings(element) element.elements.each("linescore/inning") { |element| @away_innings << element.attributes['away'] @home_innings << element.attributes['home'] } end |
#set_pitchers(element) ⇒ Object
Sets the pitchers of record (win, lose, save) from data in the master_scoreboard.xml file
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/game.rb', line 177 def set_pitchers(element) element.elements.each("winning_pitcher") do |wp| @winning_pitcher = Player.new @winning_pitcher.init_pitcher_from_scoreboard(wp) end element.elements.each("losing_pitcher") do |lp| @losing_pitcher = Player.new @losing_pitcher.init_pitcher_from_scoreboard(lp) end element.elements.each("save_pitcher") do |sp| @save_pitcher = Player.new @save_pitcher.first = sp.attributes['first'] @save_pitcher.last = sp.attributes['last'] @save_pitcher.saves = sp.attributes['saves'] end end |
#set_status(element) ⇒ Object
Sets the game status from data in the master_scoreboard.xml file
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/game.rb', line 120 def set_status(element) element.elements.each("status") { |status| @status = GameStatus.new @status.status = status.attributes['status'] @status.ind = status.attributes['ind'] @status.reason = status.attributes['reason'] @status.inning = status.attributes['inning'] @status.top_inning = status.attributes['top_inning'] @status.b = status.attributes['b'] @status.s = status.attributes['s'] @status.o = status.attributes['o'] } end |
#set_totals(element) ⇒ Object
Sets the Runs/Hits/Errors totals from data in the master_scoreboard.xml file
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/game.rb', line 145 def set_totals(element) element.elements.each("linescore/r") { |runs| @away_runs = runs.attributes['away'] @home_runs = runs.attributes['home'] } element.elements.each("linescore/h") { |hits| @away_hits = hits.attributes['away'] @home_hits = hits.attributes['home'] } element.elements.each("linescore/e") { |errs| @away_errors = errs.attributes['away'] @home_errors = errs.attributes['home'] } end |