├── lib
├── gameday_api
│ ├── eventlog.html.erb
│ ├── version.rb
│ ├── .DS_Store
│ ├── game_status.rb
│ ├── import_data.rb
│ ├── gameday_config.yml
│ ├── media_mobile.rb
│ ├── event.rb
│ ├── coach.rb
│ ├── hip.rb
│ ├── hitchart.rb
│ ├── pitching_line.rb
│ ├── scoreboard.rb
│ ├── schedule_game.rb
│ ├── cache_fetcher.rb
│ ├── media.rb
│ ├── at_bat.rb
│ ├── line_score.rb
│ ├── media_highlight.rb
│ └── inning.rb
└── gameday_api.rb
├── .gitignore
├── test
├── unit_tests
│ ├── test_file.dat
│ ├── long_running
│ │ ├── all_long_running.rb
│ │ ├── test_pitcher.rb
│ │ ├── test_player.rb
│ │ └── test_batter.rb
│ ├── test_pitch.rb
│ ├── test_batting_appearance.rb
│ ├── test_pitching_appearance.rb
│ ├── all_tests.rb
│ ├── test_roster.rb
│ ├── test_inning.rb
│ ├── test_media.rb
│ ├── test_batter.rb
│ └── test_player.rb
├── test_get_team_game.rb
├── test_boxscore_dump.rb
├── test_print_linescores_for_day.rb
├── README
├── test_import_tigers_pitchfx_to_db.rb
├── test_unique_starters.rb
├── test_all_closing_pitchers_for_detroit.rb
├── test_all_starting_pitchers_for_detroit.rb
├── test_print_batters_for_game.rb
├── test_print_player_card.rb
├── test_show_home_roster.rb
├── test_print_pitchers_for_game.rb
├── test_leadoff_and_cleanup_hitters.rb
├── test_get_all_appearances_for_robertson.rb
├── test_show_pitch_stats_for_game.rb
└── test_show_scoreboard.rb
├── doc
├── created.rid
├── logo.png
├── classes
│ ├── BattingAppearance.src
│ │ ├── M000220.html
│ │ └── M000219.html
│ ├── Gameday.src
│ │ ├── M000263.html
│ │ └── M000265.html
│ ├── Hitchart.src
│ │ └── M000001.html
│ ├── MediaMobile.src
│ │ └── M000164.html
│ ├── Team.src
│ │ ├── M000182.html
│ │ ├── M000167.html
│ │ ├── M000183.html
│ │ ├── M000170.html
│ │ ├── M000171.html
│ │ ├── M000174.html
│ │ ├── M000176.html
│ │ ├── M000178.html
│ │ └── M000180.html
│ ├── PitchingAppearance.src
│ │ ├── M000152.html
│ │ ├── M000156.html
│ │ ├── M000157.html
│ │ ├── M000153.html
│ │ └── M000155.html
│ ├── GamedayUtil.src
│ │ ├── M000142.html
│ │ ├── M000143.html
│ │ ├── M000137.html
│ │ └── M000139.html
│ ├── BoxScore.src
│ │ ├── M000055.html
│ │ ├── M000056.html
│ │ └── M000053.html
│ ├── Schedule.src
│ │ ├── M000132.html
│ │ ├── M000131.html
│ │ ├── M000133.html
│ │ └── M000134.html
│ ├── GamedayFetcher.src
│ │ ├── M000021.html
│ │ ├── M000025.html
│ │ ├── M000026.html
│ │ ├── M000037.html
│ │ ├── M000027.html
│ │ ├── M000029.html
│ │ ├── M000030.html
│ │ ├── M000036.html
│ │ ├── M000034.html
│ │ ├── M000028.html
│ │ ├── M000031.html
│ │ ├── M000033.html
│ │ ├── M000042.html
│ │ ├── M000044.html
│ │ ├── M000045.html
│ │ ├── M000047.html
│ │ ├── M000049.html
│ │ ├── M000032.html
│ │ ├── M000041.html
│ │ ├── M000035.html
│ │ ├── M000046.html
│ │ ├── M000048.html
│ │ ├── M000051.html
│ │ ├── M000038.html
│ │ ├── M000039.html
│ │ ├── M000040.html
│ │ ├── M000050.html
│ │ ├── M000022.html
│ │ ├── M000023.html
│ │ ├── M000043.html
│ │ └── M000024.html
│ ├── EventLog.src
│ │ ├── M000120.html
│ │ └── M000118.html
│ ├── Pitcher.src
│ │ ├── M000162.html
│ │ └── M000161.html
│ ├── Player.src
│ │ ├── M000062.html
│ │ └── M000063.html
│ ├── Game.src
│ │ ├── M000208.html
│ │ ├── M000209.html
│ │ ├── M000213.html
│ │ ├── M000199.html
│ │ ├── M000216.html
│ │ ├── M000203.html
│ │ ├── M000211.html
│ │ ├── M000200.html
│ │ ├── M000212.html
│ │ ├── M000217.html
│ │ ├── M000210.html
│ │ ├── M000201.html
│ │ ├── M000198.html
│ │ └── M000192.html
│ ├── GamedayUrlBuilder.src
│ │ ├── M000020.html
│ │ └── M000019.html
│ ├── CacheFetcher.src
│ │ └── M000145.html
│ ├── GamedayLocalFetcher.src
│ │ ├── M000236.html
│ │ ├── M000237.html
│ │ ├── M000248.html
│ │ ├── M000239.html
│ │ ├── M000255.html
│ │ ├── M000244.html
│ │ ├── M000256.html
│ │ ├── M000258.html
│ │ ├── M000260.html
│ │ ├── M000246.html
│ │ ├── M000257.html
│ │ ├── M000259.html
│ │ ├── M000262.html
│ │ ├── M000233.html
│ │ ├── M000234.html
│ │ ├── M000235.html
│ │ ├── M000261.html
│ │ └── M000254.html
│ ├── GamedayRemoteFetcher.src
│ │ ├── M000068.html
│ │ ├── M000069.html
│ │ ├── M000070.html
│ │ ├── M000071.html
│ │ ├── M000072.html
│ │ ├── M000083.html
│ │ ├── M000090.html
│ │ ├── M000091.html
│ │ ├── M000074.html
│ │ ├── M000079.html
│ │ ├── M000093.html
│ │ ├── M000095.html
│ │ ├── M000081.html
│ │ ├── M000092.html
│ │ ├── M000094.html
│ │ ├── M000097.html
│ │ ├── M000089.html
│ │ └── M000096.html
│ ├── Roster.src
│ │ ├── M000124.html
│ │ ├── M000123.html
│ │ ├── M000126.html
│ │ └── M000125.html
│ └── DataDownloader.src
│ │ ├── M000099.html
│ │ └── M000111.html
└── index.html
├── Rakefile
├── pkg
├── gameday_api-0.1.0.gem
└── gameday_api-0.2.0.gem
├── Gemfile
├── sample_data
├── game.xml
├── pitchers
│ ├── 465657.xml
│ ├── 444382.xml
│ └── 124604.xml
├── batters
│ ├── 150035.xml
│ ├── 461834.xml
│ └── 115229.xml
└── pbp
│ └── batters
│ └── 457133.xml
├── README.md
├── gameday_api.gemspec
└── LICENSE
/lib/gameday_api/eventlog.html.erb:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .svn
2 | lib/tmp/**/*
3 |
--------------------------------------------------------------------------------
/test/unit_tests/test_file.dat:
--------------------------------------------------------------------------------
1 | Test Data
--------------------------------------------------------------------------------
/doc/created.rid:
--------------------------------------------------------------------------------
1 | Wed, 14 Apr 2010 16:20:22 -0400
2 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env rake
2 | require "bundler/gem_tasks"
3 |
--------------------------------------------------------------------------------
/doc/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/timothyf/gameday_api/HEAD/doc/logo.png
--------------------------------------------------------------------------------
/lib/gameday_api/version.rb:
--------------------------------------------------------------------------------
1 | module GamedayApi
2 | VERSION = "0.0.1"
3 | end
4 |
--------------------------------------------------------------------------------
/lib/gameday_api/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/timothyf/gameday_api/HEAD/lib/gameday_api/.DS_Store
--------------------------------------------------------------------------------
/pkg/gameday_api-0.1.0.gem:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/timothyf/gameday_api/HEAD/pkg/gameday_api-0.1.0.gem
--------------------------------------------------------------------------------
/pkg/gameday_api-0.2.0.gem:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/timothyf/gameday_api/HEAD/pkg/gameday_api-0.2.0.gem
--------------------------------------------------------------------------------
/lib/gameday_api.rb:
--------------------------------------------------------------------------------
1 | require "gameday_api/version"
2 |
3 | module GamedayApi
4 | # Your code goes here...
5 | end
6 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | # Specify your gem's dependencies in gameday_api.gemspec
4 | gemspec
5 |
--------------------------------------------------------------------------------
/test/unit_tests/long_running/all_long_running.rb:
--------------------------------------------------------------------------------
1 | require 'test/unit'
2 | require 'test_team'
3 | require 'test_player'
4 | require 'test_batter'
5 | require 'test_pitcher'
--------------------------------------------------------------------------------
/lib/gameday_api/game_status.rb:
--------------------------------------------------------------------------------
1 | module GamedayApi
2 |
3 | class GameStatus
4 |
5 | attr_accessor :status, :ind, :reason, :inning, :top_inning, :b, :s, :o
6 |
7 | end
8 | end
9 |
--------------------------------------------------------------------------------
/lib/gameday_api/import_data.rb:
--------------------------------------------------------------------------------
1 | require 'gameday_api/db_importer'
2 |
3 | db = DbImporter.new('localhost','root','','pitchfx')
4 |
5 | #db.import_for_month('2010','04')
6 |
7 | db.import_for_date('2010','04', '05')
8 |
9 |
--------------------------------------------------------------------------------
/test/test_get_team_game.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
2 |
3 | require 'team'
4 |
5 | team = Team.new('det')
6 | games = team.games_for_date('2009', '09', '15')
7 | games.each do |game|
8 | puts game.print_linescore
9 | end
--------------------------------------------------------------------------------
/test/test_boxscore_dump.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
2 |
3 | require 'team'
4 |
5 | team = Team.new('det')
6 | games = team.games_for_date('2009', '09', '15')
7 | games[0].get_boxscore.dump_to_file
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/test/test_print_linescores_for_day.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
2 |
3 | require 'game'
4 |
5 | games = Game.find_by_date('2009','09','15')
6 |
7 | games.each do |game|
8 | puts game.print_linescore
9 | puts
10 | end
--------------------------------------------------------------------------------
/test/unit_tests/test_pitch.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../../lib")
2 |
3 | require 'test/unit'
4 | require 'pitch'
5 |
6 | class TestPitch < Test::Unit::TestCase
7 |
8 |
9 | def test_init
10 |
11 | end
12 |
13 | end
--------------------------------------------------------------------------------
/test/unit_tests/test_batting_appearance.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../../lib")
2 |
3 | require 'test/unit'
4 | require 'batting_appearance'
5 |
6 | class TestBattingAppearance < Test::Unit::TestCase
7 |
8 |
9 | def test_init
10 |
11 | end
12 |
13 | end
--------------------------------------------------------------------------------
/test/unit_tests/test_pitching_appearance.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../../lib")
2 |
3 | require 'test/unit'
4 | require 'pitching_appearance'
5 |
6 | class TestPitchingAppearance < Test::Unit::TestCase
7 |
8 |
9 | def test_init
10 |
11 | end
12 |
13 | end
--------------------------------------------------------------------------------
/test/README:
--------------------------------------------------------------------------------
1 | This directory contains tests that demonstrate usage of the gameday_api.
2 |
3 | To run a test in this directory just type the ruby command followed by the test name, like this:
4 | ruby test_get_all_closing_pitchers_for_detroit.rb
5 |
6 | Feel free to incorporate any code you find here into your own programs.
7 |
8 |
--------------------------------------------------------------------------------
/test/test_import_tigers_pitchfx_to_db.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
2 |
3 | require 'db_importer'
4 |
5 | importer = DbImporter.new('localhost', 'root', '', 'pitchfx')
6 |
7 | #importer.import_for_month('2010', '04')
8 |
9 | importer.import_team_for_month('det', '2010', '04')
10 |
11 | #importer.import_for_game('2009_09_09_detmlb_kcamlb_1')
12 |
--------------------------------------------------------------------------------
/lib/gameday_api/gameday_config.yml:
--------------------------------------------------------------------------------
1 | # If you are behind a firewall, set a proxy here
2 | proxy:
3 | # host: 10.0.6.251
4 | # port: 3128
5 |
6 | # Do you want to retrieve the Gameday files from the gd2.mlb.com server, or from local storage
7 | # uncomment the desired fetcher
8 | #fetcher: remote
9 | fetcher: local
10 |
11 | # Move FILEBASEPATH into here
12 |
13 | # Move Gameday BASE URL into here
14 |
15 |
--------------------------------------------------------------------------------
/lib/gameday_api/media_mobile.rb:
--------------------------------------------------------------------------------
1 | module GamedayApi
2 |
3 | class MediaMobile
4 |
5 | attr_accessor :id, :date, :type, :top_play, :player_id
6 | attr_accessor :team_id, :headline, :duration, :thumb_url
7 | attr_accessor :iphone_low_url, :iphone_hi_url
8 | attr_accessor :h264_low_url, :h264_hi_url
9 |
10 | def initialize(element)
11 |
12 | end
13 |
14 |
15 | end
16 | end
--------------------------------------------------------------------------------
/lib/gameday_api/event.rb:
--------------------------------------------------------------------------------
1 | module GamedayApi
2 | class Event
3 |
4 | attr_accessor :number, :inning, :description, :team
5 |
6 | def load(element, home_or_away)
7 | @xml_doc = element
8 | @team = home_or_away
9 | @number = element.attributes["number"]
10 | @inning = element.attributes["inning"]
11 | @description = element.attributes["description"]
12 | end
13 |
14 |
15 | end
16 | end
--------------------------------------------------------------------------------
/test/test_unique_starters.rb:
--------------------------------------------------------------------------------
1 | # This test will print a list of the pitchers who have started at least
2 | # one game during the 2009 season.
3 |
4 |
5 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
6 |
7 | require 'team'
8 |
9 | team = Team.new('det')
10 | pitchers = team.get_starters_unique('2009')
11 | count = 1
12 | pitchers.each do |appearance|
13 | puts count.to_s + ' ' + appearance.pitcher_name
14 | count = count + 1
15 | end
16 |
--------------------------------------------------------------------------------
/test/test_all_closing_pitchers_for_detroit.rb:
--------------------------------------------------------------------------------
1 | # This test will print a list of the starting pitchers for each of the Detroit
2 | # Tigers games from the 2009 season.
3 |
4 |
5 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
6 |
7 | require 'team'
8 |
9 | team = Team.new('det')
10 | pitchers = team.get_close_pitcher_appearances_by_year('2009')
11 | count = 1
12 | pitchers.each do |appearance|
13 | puts count.to_s + ' ' + appearance.pitcher_name
14 | count = count + 1
15 | end
16 |
--------------------------------------------------------------------------------
/test/test_all_starting_pitchers_for_detroit.rb:
--------------------------------------------------------------------------------
1 | # This test will print a list of the starting pitchers for each of the Detroit
2 | # Tigers games from the 2009 season.
3 |
4 |
5 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
6 |
7 | require 'team'
8 |
9 | team = Team.new('det')
10 | pitchers = team.get_start_pitcher_appearances_by_year('2009')
11 | count = 1
12 | pitchers.each do |appearance|
13 | puts count.to_s + ' ' + appearance.pitcher_name
14 | count = count + 1
15 | end
16 |
--------------------------------------------------------------------------------
/test/test_print_batters_for_game.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
2 |
3 | require 'team'
4 |
5 | team = Team.new('det')
6 | games = team.games_for_date('2009', '09', '15')
7 |
8 | lineups = games[0].get_lineups
9 |
10 | visitors = lineups[0]
11 | home = lineups[1]
12 |
13 | puts 'Visitors'
14 | visitors.each do |batter|
15 | puts batter.batter_name
16 | end
17 | puts
18 | puts
19 | puts 'Home'
20 | home.each do |batter|
21 | puts batter.batter_name
22 | end
23 |
--------------------------------------------------------------------------------
/test/unit_tests/long_running/test_pitcher.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../../../lib")
2 |
3 | require 'test/unit'
4 | require 'pitcher'
5 |
6 | class TestPitcher < Test::Unit::TestCase
7 |
8 |
9 | def setup
10 | if !@pitcher
11 | @pitcher = Pitcher.new
12 | @pitcher.load_from_id('2009_09_20_detmlb_minmlb_1', '434378')
13 | assert @pitcher.first_name == 'Justin'
14 | assert @pitcher.last_name == 'Verlander'
15 | end
16 | end
17 |
18 |
19 | end
--------------------------------------------------------------------------------
/lib/gameday_api/coach.rb:
--------------------------------------------------------------------------------
1 | # This class represents a single MLB coach
2 | module GamedayApi
3 | class Coach
4 |
5 | attr_accessor :position, :first, :last, :id, :num
6 |
7 |
8 | def init(element)
9 | self.id = element.attributes['id']
10 | self.first = element.attributes['first']
11 | self.last = element.attributes['last']
12 | self.num= element.attributes['num']
13 | self.position = element.attributes['position']
14 | end
15 |
16 | end
17 | end
18 |
19 |
--------------------------------------------------------------------------------
/test/test_print_player_card.rb:
--------------------------------------------------------------------------------
1 | # This test prints information and statistics for a player in a format similar
2 | # to what you would see on the back of a baseball card
3 | # Only the past 3 seasons of statistics are included.
4 |
5 | # Display card data for Curtis Granderson
6 |
7 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
8 |
9 | require 'team'
10 |
11 | team = Team.new('det')
12 |
13 | #(2007..2009).each do |year|
14 | roster = team.opening_day_roster(2009)
15 | player = roster.find_player_by_last_name('Granderson')
16 | puts player.first + ' ' + player.last
17 | #end
18 |
19 |
20 |
--------------------------------------------------------------------------------
/lib/gameday_api/hip.rb:
--------------------------------------------------------------------------------
1 | module GamedayApi
2 |
3 | class Hip
4 |
5 | attr_accessor :des, :x, :y, :batter_id, :pitcher_id, :hip_type, :team, :inning
6 |
7 |
8 | def initialize(element)
9 | @des = element.attributes["des"]
10 | @x = element.attributes["x"]
11 | @y = element.attributes["y"]
12 | @batter_id = element.attributes["batter"]
13 | @pitcher_id = element.attributes["pitcher"]
14 | @hip_type = element.attributes["type"]
15 | @team = element.attributes["team"]
16 | @inning = element.attributes["inning"]
17 | end
18 |
19 |
20 | end
21 | end
--------------------------------------------------------------------------------
/lib/gameday_api/hitchart.rb:
--------------------------------------------------------------------------------
1 | require 'gameday_api/hip'
2 |
3 | module GamedayApi
4 |
5 | class Hitchart
6 |
7 | attr_accessor :hips, :gid
8 |
9 |
10 | def initialize
11 | @hips = []
12 | end
13 |
14 |
15 | def load_from_gid(gid)
16 | @gid = gid
17 | @xml_data = GamedayFetcher.fetch_inning_hit(gid)
18 | @xml_doc = REXML::Document.new(@xml_data)
19 | if @xml_doc.root
20 | @xml_doc.elements.each("hitchart/hip") do |element|
21 | hip = Hip.new(element)
22 | @hips << hip
23 | end
24 | end
25 | end
26 |
27 |
28 | end
29 | end
--------------------------------------------------------------------------------
/test/test_show_home_roster.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
2 |
3 | require 'team'
4 |
5 | team = Team.new('det')
6 | games = team.games_for_date('2009', '09', '15')
7 |
8 | players = games[0].get_rosters
9 |
10 | puts 'PLAYERS'
11 | count = 1
12 | players[1].players.each do |player|
13 | puts count.to_s + ' ' + player.first + ' ' + player.last + ' ' + player.position + ' ' + player.dob
14 | count = count + 1
15 | end
16 |
17 | puts ''
18 | puts 'COACHES'
19 | count = 1
20 | players[1].coaches.each do |coach|
21 | puts count.to_s + ' ' + coach.first + ' ' + coach.last + ' ' + coach.position
22 | count = count + 1
23 | end
24 |
--------------------------------------------------------------------------------
/test/unit_tests/all_tests.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../../lib")
2 |
3 | require 'gameday_util'
4 |
5 | GamedayUtil.set_fetcher('remote')
6 |
7 | require 'test/unit'
8 | require 'test_gameday_util'
9 | require 'test_gameday_url_builder'
10 | require 'test_team'
11 | require 'test_game'
12 | require 'test_boxscore'
13 | require 'test_player'
14 | require 'test_gameday_fetcher'
15 | require 'test_batter'
16 | require 'test_pitcher'
17 | require 'test_event_log'
18 | require 'test_pitch'
19 | require 'test_batting_appearance'
20 | require 'test_pitching_appearance'
21 | require 'test_inning'
22 | require 'test_roster'
23 | require 'test_media'
24 |
--------------------------------------------------------------------------------
/test/unit_tests/long_running/test_player.rb:
--------------------------------------------------------------------------------
1 | $: << File.expand_path(File.dirname(__FILE__) + "/../../../lib")
2 |
3 | require 'test/unit'
4 | require 'player'
5 |
6 | class TestPlayer < Test::Unit::TestCase
7 |
8 |
9 | def setup
10 | if !@player
11 | @player = Player.new
12 | @player.load_from_id('2009_09_20_detmlb_minmlb_1', '434158')
13 | end
14 | end
15 |
16 |
17 | def test_long_running
18 | get_all_appearances_test
19 | end
20 |
21 |
22 | def get_all_appearances_test
23 | appearances = @player.get_all_appearances('2009')
24 | assert_not_nil appearances
25 | assert appearances.length == 160
26 | end
27 |
28 |
29 | end
--------------------------------------------------------------------------------
/sample_data/game.xml:
--------------------------------------------------------------------------------
1 |
# File lib/batting_appearance.rb, line 51 14 | def get_atbats 15 | 16 | end17 | 18 | -------------------------------------------------------------------------------- /test/test_leadoff_and_cleanup_hitters.rb: -------------------------------------------------------------------------------- 1 | # This test will print two lists. The first list will be of the leadoff hitters for each of the Detroit 2 | # Tigers games from the 2009 season. The second list will be of the cleanup (4th) hitters for each of 3 | # the Tigers 2009 games. 4 | 5 | 6 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib") 7 | 8 | require 'team' 9 | 10 | team = Team.new('det') 11 | hitters = team.get_leadoff_hitters_by_year('2009') 12 | count = 1 13 | hitters.each do |appearance| 14 | puts count.to_s + ' ' + appearance.batter_name 15 | count = count + 1 16 | end 17 | 18 | cleanup = team.get_cleanup_hitters_by_year('2009') 19 | count = 1 20 | cleanup.each do |appearance| 21 | puts count.to_s + ' ' + appearance.batter_name 22 | count = count + 1 23 | end 24 | -------------------------------------------------------------------------------- /doc/classes/Gameday.src/M000263.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday.rb, line 16 14 | def initialize 15 | super 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/Hitchart.src/M000001.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/hitchart.rb, line 8 14 | def initialize 15 | @hips = [] 16 | end17 | 18 | -------------------------------------------------------------------------------- /lib/gameday_api/scoreboard.rb: -------------------------------------------------------------------------------- 1 | require 'gameday_api/gameday_fetcher' 2 | 3 | module GamedayApi 4 | 5 | class Scoreboard 6 | 7 | attr_accessor :games # An array of Game objects representing all of the games played on this date 8 | attr_accessor :year, :month, :day 9 | 10 | def load_for_date(year, month, day) 11 | @games = [] 12 | @year = year 13 | @month = month 14 | @day = day 15 | @xml_data = GamedayFetcher.fetch_scoreboard(year, month, day) 16 | @xml_doc = REXML::Document.new(@xml_data) 17 | 18 | @xml_doc.elements.each("games/game") { |element| 19 | game = Game.new(element.attributes['gameday']) 20 | game.load_from_scoreboard(element) 21 | @games << game 22 | } 23 | end 24 | 25 | end 26 | end -------------------------------------------------------------------------------- /doc/classes/MediaMobile.src/M000164.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/media_mobile.rb, line 8 14 | def initialize(element) 15 | 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/Team.src/M000182.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/team.rb, line 269 14 | def players_for_season(year) 15 | 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/Team.src/M000167.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/team.rb, line 73 14 | def self.teams 15 | @@abrevs 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/PitchingAppearance.src/M000152.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/pitching_appearance.rb, line 34 14 | def start? 15 | start 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 13 |
# File lib/team.rb, line 275 14 | def get_games_for_month(year, month) 15 | 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayUtil.src/M000142.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_util.rb, line 76 14 | def self.read_file(filename) 15 | 16 | end17 | 18 | -------------------------------------------------------------------------------- /test/unit_tests/long_running/test_batter.rb: -------------------------------------------------------------------------------- 1 | $: << File.expand_path(File.dirname(__FILE__) + "/../../../lib") 2 | 3 | require 'test/unit' 4 | require 'batter' 5 | 6 | class TestBatter < Test::Unit::TestCase 7 | 8 | 9 | def setup 10 | if !@batter 11 | @batter = Batter.new 12 | @batter.load_from_id('2009_09_20_detmlb_minmlb_1', '434158') 13 | end 14 | end 15 | 16 | 17 | def test_long_running 18 | get_multihit_appearances_test 19 | #at_bats_count_test 20 | end 21 | 22 | 23 | def get_multihit_appearances_test 24 | appearances = @batter.get_multihit_appearances('2009') 25 | assert_not_nil appearances 26 | assert appearances.length == 40 27 | end 28 | 29 | 30 | def at_bats_count_test 31 | ab_count = @batter.at_bats_count 32 | assert ab_count == 631 33 | end 34 | 35 | 36 | end -------------------------------------------------------------------------------- /doc/classes/BoxScore.src/M000055.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/box_score.rb, line 63 14 | def get_leadoff_hitters 15 | find_hitters("batter") 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/PitchingAppearance.src/M000156.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/pitching_appearance.rb, line 73 14 | def pitch_count 15 | get_pitches.length 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/Schedule.src/M000132.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/schedule.rb, line 20 14 | def get_opening_day 15 | games[0].date 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/BoxScore.src/M000056.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/box_score.rb, line 71 14 | def get_cleanup_hitters 15 | find_hitters("batter[@bo='400']") 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000021.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 57 14 | def self.fetcher 15 | GamedayRemoteFetcher 16 | #GamedayLocalFetcher 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/Schedule.src/M000131.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/schedule.rb, line 13 14 | def initialize(year) 15 | @games = [] 16 | read_file(get_sked_filename(year)) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000025.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 82 14 | def self.fetch_bench(gid) 15 | fetcher.fetch_bench(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000026.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 89 14 | def self.fetch_bencho(gid) 15 | fetcher.fetch_bencho(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000037.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 161 14 | def self.fetch_plays(gid) 15 | fetcher.fetch_plays(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000027.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 96 14 | def self.fetch_boxscore(gid) 15 | fetcher.fetch_boxscore(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000029.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 110 14 | def self.fetch_eventlog(gid) 15 | fetcher.fetch_eventlog(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000030.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 116 14 | def self.fetch_game_xml(gid) 15 | fetcher.fetch_game_xml(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000036.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 154 14 | def self.fetch_players(gid) 15 | fetcher.fetch_players(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000034.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 141 14 | def self.fetch_linescore(gid) 15 | fetcher.fetch_linescore(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000028.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 103 14 | def self.fetch_emailsource(gid) 15 | fetcher.fetch_emailsource(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000031.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 121 14 | def self.fetch_game_events(gid) 15 | fetcher.fetch_game_events(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000033.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 134 14 | def self.fetch_gamedaysyn(gid) 15 | fetcher.fetch_gamedaysyn(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000042.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 190 14 | def self.fetch_inning_hit(gid) 15 | fetcher.fetch_inning_hit(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/BoxScore.src/M000053.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/box_score.rb, line 46 14 | def dump_to_file 15 | GamedayUtil.save_file("boxscore.html", to_html('boxscore.html.erb')) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000044.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 202 14 | def self.fetch_batters_page(gid) 15 | fetcher.fetch_batters_page(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000045.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 208 14 | def self.fetch_pitchers_page(gid) 15 | fetcher.fetch_pitchers_page(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000047.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 218 14 | def self.fetch_media_mobile(gid) 15 | fetcher.fetch_media_mobile(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000049.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 228 14 | def self.fetch_onbase_plays(gid) 15 | fetcher.fetch_onbase_plays(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000032.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 127 14 | def self.fetch_gamecenter_xml(gid) 15 | fetcher.fetch_gamecenter_xml(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000041.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 184 14 | def self.fetch_inning_scores(gid) 15 | fetcher.fetch_inning_scores(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000035.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 148 14 | def self.fetch_miniscoreboard(gid) 15 | fetcher.fetch_miniscoreboard(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000046.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 213 14 | def self.fetch_media_highlights(gid) 15 | fetcher.fetch_media_highlights(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000048.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 223 14 | def self.fetch_onbase_linescore(gid) 15 | fetcher.fetch_onbase_linescore(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000051.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 238 14 | def self.fetch_notifications_full(gid) 15 | fetcher.fetch_notifications_full(gid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /sample_data/pitchers/465657.xml: -------------------------------------------------------------------------------- 1 |
# File lib/event_log.rb, line 88 14 | def dump_to_file 15 | GamedayUtil.save_file("eventlog.html", self.to_html('eventlog.html.erb')) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/Schedule.src/M000133.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/schedule.rb, line 26 14 | def get_season_length 15 | games[games.size-1].home_game_number.to_i 16 | end17 | 18 | -------------------------------------------------------------------------------- /lib/gameday_api/schedule_game.rb: -------------------------------------------------------------------------------- 1 | module GamedayApi 2 | 3 | # This class represents a single game from a game schedule 4 | # This class is used in conjunction with the Schedule class. 5 | # This is not the class you would use to retrieve game statistics. 6 | class ScheduleGame 7 | 8 | attr_accessor :date, :day_of_week, :away_team_abbrev, :away_league, :away_game_number 9 | attr_accessor :home_team_abbrev, :home_league, :home_game_number, :day_or_night 10 | 11 | 12 | def initialize(line) 13 | temp = line.split(',') 14 | @date = temp[0].tr_s('"', '').strip 15 | @day_of_week = temp[2].tr_s('"', '').strip 16 | @away_team_abbrev = temp[3].tr_s('"', '').strip 17 | @away_league = temp[4].tr_s('"', '').strip 18 | @away_game_number = temp[5].tr_s('"', '').strip 19 | @home_team_abbrev = temp[6].tr_s('"', '').strip 20 | @home_league = temp[7].tr_s('"', '').strip 21 | @home_game_number = temp[8].tr_s('"', '').strip 22 | @day_or_night = temp[9].tr_s('"', '').strip 23 | end 24 | 25 | end 26 | end -------------------------------------------------------------------------------- /test/unit_tests/test_media.rb: -------------------------------------------------------------------------------- 1 | $: << File.expand_path(File.dirname(__FILE__) + "/../../lib") 2 | 3 | require 'test/unit' 4 | require 'media' 5 | 6 | class TestTeam < Test::Unit::TestCase 7 | 8 | 9 | def test_load_from_id 10 | media = Media.new 11 | media.load_from_id('2009_09_20_detmlb_minmlb_1') 12 | assert_not_nil media.highlights 13 | assert_not_nil media.mobile 14 | assert media.highlights.length == 6 15 | assert media.highlights[0].headline == "Punto's RBI single" 16 | assert media.highlights[0].duration == "00:00:37" 17 | assert media.highlights[0].thumb_url == "http://mediadownloads.mlb.com/mlbam/2009/09/20/rth_6751897_th_7.jpg" 18 | assert media.highlights[0].res_400_url == "http://mediadownloads.mlb.com/mlbam/2009/09/20/mlbtv_detmin_6751897_400K.mp4" 19 | assert media.highlights[0].res_500_url == "http://mediadownloads.mlb.com/mlbam/2009/09/20/rth_detmin_6751897_500.mp4" 20 | assert media.highlights[0].res_800_url == "http://mediadownloads.mlb.com/mlbam/2009/09/20/mlbtv_detmin_6751897_800K.mp4" 21 | end 22 | 23 | 24 | end -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000038.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 167 14 | def self.fetch_batter(gid, pid) 15 | fetcher.fetch_batter(gid, pid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000039.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 173 14 | def self.fetch_pitcher(gid, pid) 15 | fetcher.fetch_pitcher(gid, pid) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000040.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 178 14 | def self.fetch_inningx(gid, inning_num) 15 | fetcher.fetch_inningx(gid, inning_num) 16 | end17 | 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Timothy Fisher 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /test/test_show_pitch_stats_for_game.rb: -------------------------------------------------------------------------------- 1 | # In this test we will print out detailed pitch statistics for 2 | # each of the pitchers who appeared in the specified game between 3 | # Detroit and Kansas City 4 | 5 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib") 6 | 7 | require 'game' 8 | 9 | def print_stats(pa) 10 | puts pa.pitcher_name 11 | pc = pa.pitch_count 12 | puts " pitches: " + pc.to_s 13 | pitches = pa.set_pitch_stats 14 | puts " balls: " + pa.b.to_s + ', ' + ((pa.b.to_f/pc.to_f)*100).to_i.to_s + '%' 15 | puts " strikes: " + pa.s.to_s + ', ' + ((pa.s.to_f/pc.to_f)*100).to_i.to_s + '%' 16 | puts " in-play: " + pa.x.to_s + ', ' + ((pa.x.to_f/pc.to_f)*100).to_i.to_s + '%' 17 | puts " max speed: " + pa.max_speed.to_s 18 | puts " min speed: " + pa.min_speed.to_s 19 | end 20 | 21 | game = Game.new('2010_04_12_kcamlb_detmlb_1') 22 | pitchers = game.get_pitching 23 | 24 | puts 'Visitors:' 25 | pitchers[0].each do |pa| 26 | print_stats(pa) 27 | end 28 | puts 29 | puts 30 | puts 'Home:' 31 | pitchers[1].each do |pa| 32 | print_stats(pa) 33 | end 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /doc/classes/Pitcher.src/M000162.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/pitcher.rb, line 69 14 | def get_game 15 | if !@game 16 | @game = Game.new(@gid) 17 | end 18 | @game 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000050.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 233 14 | def self.fetch_notifications_inning(gid, inning) 15 | fetcher.fetch_notifications_inning(gid, inning) 16 | end17 | 18 | -------------------------------------------------------------------------------- /lib/gameday_api/cache_fetcher.rb: -------------------------------------------------------------------------------- 1 | require 'net/http' 2 | require 'md5' 3 | 4 | module GamedayApi 5 | class CacheFetcher 6 | 7 | def initialize(cache_dir=File.expand_path(File.dirname(__FILE__)) + '/tmp') 8 | # this is the dir where we store our cache 9 | @cache_dir = cache_dir 10 | end 11 | 12 | 13 | def fetch(url) 14 | file = MD5.hexdigest(url) 15 | file_path = File.join("", @cache_dir, file) 16 | # we check if the file -- a MD5 hexdigest of the URL -- exists 17 | # in the dir. If it does we just read data from the file and return 18 | if !File.exists? file_path 19 | #puts 'Not found in cache' 20 | # if the file does not exist (or if the data is not fresh), we 21 | # make an HTTP request and save it to a file 22 | #puts 'Fetching file from internet...' 23 | File.open(file_path, "w") do |data| 24 | data << Net::HTTP.get_response(URI.parse(url)).body 25 | end 26 | else 27 | #puts 'Using cache' 28 | end 29 | return File.new(file_path) 30 | end 31 | 32 | end 33 | end -------------------------------------------------------------------------------- /doc/classes/Player.src/M000062.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/player.rb, line 75 14 | def get_team 15 | if !@team_obj 16 | @team_obj = Team.new(@team_abbrev) 17 | end 18 | @team_obj 19 | end20 | 21 | -------------------------------------------------------------------------------- /sample_data/pitchers/444382.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 |
# File lib/gameday_fetcher.rb, line 63 14 | def self.fetch_epg(year, month, day) 15 | fetcher.fetch_epg(year, month, day) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/PitchingAppearance.src/M000157.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/pitching_appearance.rb, line 78 14 | def get_game 15 | if !@game 16 | @game = Game.new(@gid) 17 | end 18 | @game 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/Game.src/M000208.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 353 14 | def get_lineups 15 | results = [] 16 | results << get_batters('away') 17 | results << get_batters('home') 18 | end19 | 20 | -------------------------------------------------------------------------------- /sample_data/batters/150035.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 |
# File lib/game.rb, line 363 14 | def get_pitching 15 | results = [] 16 | results << get_pitchers('away') 17 | results << get_pitchers('home') 18 | end19 | 20 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000023.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 70 14 | def self.fetch_scoreboard(year, month, day) 15 | fetcher.fetch_scoreboard(year, month, day) 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayFetcher.src/M000043.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_fetcher.rb, line 196 14 | def self.fetch_games_page(year, month, day) 15 | fetcher.fetch_games_page(year, month, day) 16 | end17 | 18 | -------------------------------------------------------------------------------- /sample_data/pitchers/124604.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 |
# File lib/gameday_fetcher.rb, line 75 14 | def self.fetch_day_highlights(year, month, day) 15 | fetcher.fetch_day_highlights(year, month, day) 16 | end17 | 18 | -------------------------------------------------------------------------------- /sample_data/batters/115229.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 |
# File lib/player.rb, line 85 14 | def get_games_for_season(year) 15 | if !@games 16 | @games = get_team.all_games(year) 17 | end 18 | @games 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayUrlBuilder.src/M000020.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_url_builder.rb, line 108 14 | def self.build_month_url(year, month) 15 | set_date_vars(year, month, nil) 16 | "#{Gameday::GD2_MLB_BASE}/mlb/year_#{@@year}/month_#{@@month}/" 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/Game.src/M000213.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 401 14 | def get_media 15 | if !@media 16 | @media = Media.new 17 | @media.load_from_id(@gid) 18 | end 19 | @media 20 | end21 | 22 | -------------------------------------------------------------------------------- /lib/gameday_api/media.rb: -------------------------------------------------------------------------------- 1 | require 'gameday_api/gameday_fetcher' 2 | require 'gameday_api/media_highlight' 3 | require 'gameday_api/media_mobile' 4 | 5 | 6 | module GamedayApi 7 | 8 | class Media 9 | 10 | attr_accessor :gid, :highlights, :mobile 11 | 12 | 13 | def load_from_id(gid) 14 | @gid = gid 15 | @highlights = [] 16 | @mobile = [] 17 | begin 18 | @xml_highlights = GamedayFetcher.fetch_media_highlights(gid) 19 | @xml_doc = REXML::Document.new(@xml_highlights) 20 | if @xml_doc.root 21 | @xml_doc.elements.each("highlights/media") do |element| 22 | highlight = MediaHighlight.new(element) 23 | @highlights << highlight 24 | end 25 | end 26 | 27 | @xml_mobile = GamedayFetcher.fetch_media_mobile(gid) 28 | @xml_doc = REXML::Document.new(@xml_mobile) 29 | if @xml_doc.root 30 | @xml_doc.elements.each("mobile/media") do |element| 31 | mobile = MediaMobile.new(element) 32 | @mobile << mobile 33 | end 34 | end 35 | rescue 36 | puts "Could not find media for #{gid}" 37 | end 38 | end 39 | 40 | 41 | end 42 | end -------------------------------------------------------------------------------- /doc/classes/Game.src/M000199.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 235 14 | def get_eventlog 15 | if !@eventlog 16 | @eventlog = EventLog.new 17 | @eventlog.load_from_id(@gid) 18 | end 19 | @eventlog 20 | end21 | 22 | -------------------------------------------------------------------------------- /doc/classes/Game.src/M000216.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 440 14 | def get_hitchart 15 | if !@hitchart 16 | @hitchart = Hitchart.new 17 | @hitchart.load_from_gid(@gid) 18 | end 19 | @hitchart 20 | end21 | 22 | -------------------------------------------------------------------------------- /doc/classes/GamedayUrlBuilder.src/M000019.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_url_builder.rb, line 102 14 | def self.build_day_url(year, month, day) 15 | set_date_vars(year, month, day) 16 | "#{Gameday::GD2_MLB_BASE}/mlb/year_#{@@year}/month_#{@@month}/day_#{@@day}/" 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/EventLog.src/M000118.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/event_log.rb, line 71 14 | def dump 15 | (1..@max_inning).each do |inning| 16 | dump_inning(inning.to_s) 17 | end 18 | end19 | 20 | -------------------------------------------------------------------------------- /doc/classes/Game.src/M000203.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 285 14 | def get_starting_pitchers 15 | results = [] 16 | results << get_pitchers('away')[0] 17 | results << get_pitchers('home')[0] 18 | end19 | 20 | -------------------------------------------------------------------------------- /doc/classes/CacheFetcher.src/M000145.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/cache_fetcher.rb, line 6 14 | def initialize(cache_dir=File.expand_path(File.dirname(__FILE__)) + '/tmp') 15 | # this is the dir where we store our cache 16 | @cache_dir = cache_dir 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayUtil.src/M000143.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_util.rb, line 81 14 | def self.save_file(filename, data) 15 | File.open(filename, 'w') {|f| f.write(data) } 16 | end17 | 18 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000236.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 34 14 | def self.fetch_bench(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/bench.xml' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000237.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 42 14 | def self.fetch_bencho(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/benchO.xml' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000248.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 132 14 | def self.fetch_plays(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/plays.xml' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000239.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 59 14 | def self.fetch_emailsource(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/emailSource.xml' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000255.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 185 14 | def self.fetch_batters_page(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/batters.html' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000244.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 99 14 | def self.fetch_gamedaysyn(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/gameday_Syn.xml' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000256.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 192 14 | def self.fetch_pitchers_page(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/pitchers.html' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000258.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 204 14 | def self.fetch_media_mobile(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/media/mobile.xml' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000260.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 216 14 | def self.fetch_onbase_plays(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/onbase/plays.xml' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /lib/gameday_api/at_bat.rb: -------------------------------------------------------------------------------- 1 | require 'gameday_api/pitch' 2 | 3 | module GamedayApi 4 | # This class represents a single atbat during a single game 5 | class AtBat 6 | 7 | attr_accessor :gid, :inning, :away_team, :home_team 8 | attr_accessor :num, :b, :s, :o, :batter_id, :stand, :b_height, :pitcher_id, :p_throws, :des, :event 9 | attr_accessor :pitches 10 | 11 | def init(element, gid, inning) 12 | @inning = inning 13 | @xml_doc = element 14 | @gid = gid 15 | @num = element.attributes["num"] 16 | @b = element.attributes["b"] 17 | @s = element.attributes["s"] 18 | @o = element.attributes["o"] 19 | @batter_id = element.attributes["batter"] 20 | @stand = element.attributes["stand"] 21 | @b_height = element.attributes["b_height"] 22 | @pitcher_id = element.attributes["pitcher"] 23 | @p_throws = element.attributes["p_throws"] 24 | @des = element.attributes["des"] 25 | @event = element.attributes["event"] 26 | set_pitches(element) 27 | end 28 | 29 | 30 | def set_pitches(element) 31 | @pitches = [] 32 | element.elements.each("pitch") do |element| 33 | pitch = Pitch.new 34 | pitch.init(element) 35 | @pitches << pitch 36 | end 37 | end 38 | 39 | 40 | end 41 | end -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000068.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 18 14 | def self.fetch_epg(year, month, day) 15 | url = GamedayUrlBuilder.build_epg_url(year, month, day) 16 | fetch(url) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000246.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 116 14 | def self.fetch_miniscoreboard(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/miniscoreboard.xml' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000257.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 198 14 | def self.fetch_media_highlights(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/media/highlights.xml' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000259.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 210 14 | def self.fetch_onbase_linescore(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + '/onbase/linescore.xml' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000069.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 26 14 | def self.fetch_scoreboard(year, month, day) 15 | url = GamedayUrlBuilder.build_scoreboard_url(year, month, day) 16 | fetch(url) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/Team.src/M000170.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/team.rb, line 121 14 | def all_home_games(year) 15 | games = all_games(year) 16 | results = games.select {|g| g.home_team_abbrev == @abrev } 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/Team.src/M000171.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/team.rb, line 128 14 | def all_away_games(year) 15 | games = all_games(year) 16 | results = games.select {|g| g.visit_team_abbrev == @abrev } 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000070.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 32 14 | def self.fetch_day_highlights(year, month, day) 15 | url = GamedayUrlBuilder.build_day_highlights_url(year, month, day) 16 | fetch(url) 17 | end18 | 19 | -------------------------------------------------------------------------------- /test/test_show_scoreboard.rb: -------------------------------------------------------------------------------- 1 | # This test will print the scoreboard containing linescores for the specified date 2 | 3 | 4 | $: << File.expand_path(File.dirname(__FILE__) + "/../lib") 5 | 6 | require 'scoreboard' 7 | 8 | sb = Scoreboard.new 9 | sb.load_for_date('2009', '09', '20') 10 | 11 | puts 'Games played = ' + sb.games.length.to_s 12 | 13 | sb.games.each do |game| 14 | away_innings_string = ' ' 15 | game.away_innings.each do |inning| 16 | away_innings_string += inning 17 | end 18 | home_innings_string = ' ' 19 | game.home_innings.each do |inning| 20 | if inning 21 | home_innings_string += inning 22 | end 23 | end 24 | # add in totals 25 | away_innings_string += ' ' + game.away_runs + ' ' + game.away_hits + ' ' + game.away_errors 26 | home_innings_string += ' ' + game.home_runs + ' ' + game.home_hits + ' ' + game.home_errors 27 | 28 | puts game.away_team_city + away_innings_string 29 | puts game.home_team_city + home_innings_string 30 | puts 'Winning Pitcher: ' + game.winning_pitcher.first + ' ' + game.winning_pitcher.last 31 | puts 'Losing Pitcher: ' + game.losing_pitcher.first + ' ' + game.losing_pitcher.last 32 | if game.save_pitcher.last && game.save_pitcher.last != '' 33 | puts 'Save Pitcher: ' + game.save_pitcher.first + ' ' + game.save_pitcher.last 34 | end 35 | puts '' 36 | end -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000262.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 228 14 | def self.fetch_notifications_full(gid) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + "/notifications/notifications_full.xml" 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /lib/gameday_api/line_score.rb: -------------------------------------------------------------------------------- 1 | module GamedayApi 2 | 3 | # This class contains data representing a linescore for a single game. 4 | class LineScore 5 | 6 | attr_accessor :xml_doc 7 | attr_accessor :away_team_runs, :home_team_runs, :away_team_hits, :home_team_hits, :away_team_errors, :home_team_errors 8 | attr_accessor :innings 9 | 10 | # Initialize this instance from an XML element containing linescore data. 11 | def init(element) 12 | @xml_doc = element 13 | self.away_team_runs = element.attributes["away_team_runs"] 14 | self.away_team_hits = element.attributes["away_team_hits"] 15 | self.away_team_errors = element.attributes["away_team_errors"] 16 | 17 | self.home_team_runs = element.attributes["home_team_runs"] 18 | self.home_team_hits = element.attributes["home_team_hits"] 19 | self.home_team_errors = element.attributes["home_team_errors"] 20 | 21 | # Set score by innings 22 | set_innings 23 | end 24 | 25 | 26 | def set_innings 27 | @innings = [] 28 | @xml_doc.elements.each("inning_line_score") do |element| 29 | score = [] 30 | score.push element.attributes["away"] 31 | score.push element.attributes["home"] 32 | @innings.push score 33 | end 34 | end 35 | 36 | 37 | 38 | end 39 | end 40 | 41 | -------------------------------------------------------------------------------- /sample_data/pbp/batters/457133.xml: -------------------------------------------------------------------------------- 1 |
# File lib/game.rb, line 384 14 | def get_score 15 | results = [] 16 | ls = get_boxscore.linescore 17 | results << ls.away_team_runs 18 | results << ls.home_team_runs 19 | results 20 | end21 | 22 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000233.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 12 14 | def self.fetch_epg(year, month, day) 15 | path = GamedayPathBuilder.build_epg_path(year, month, day) 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/Game.src/M000200.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 245 14 | def get_boxscore 15 | if !@boxscore 16 | box = BoxScore.new 17 | box.load_from_id(self.gid) 18 | @boxscore = box 19 | end 20 | @boxscore 21 | end22 | 23 | -------------------------------------------------------------------------------- /lib/gameday_api/media_highlight.rb: -------------------------------------------------------------------------------- 1 | module GamedayApi 2 | 3 | class MediaHighlight 4 | 5 | attr_accessor :id, :date, :type, :v 6 | attr_accessor :headline, :duration, :thumb_url 7 | attr_accessor :res_400_url, :res_500_url, :res_800_url 8 | 9 | def initialize(element) 10 | @id = element.attributes['id'] 11 | @date = element.attributes['date'] 12 | @type = element.attributes['type'] 13 | @v = element.attributes['v'] 14 | @headline = element.elements["headline"].text 15 | @duration = element.elements["duration"].text 16 | @thumb_url = element.elements["thumb"].text 17 | if element.elements["url[@playback_scenario='FLASH_400K_600X338']"] 18 | @res_400_url = element.elements["url[@playback_scenario='FLASH_400K_600X338']"].text 19 | else 20 | @res_400_url = nil 21 | end 22 | if element.elements["url[@playback_scenario='FLASH_500K_512X288']"] 23 | @res_500_url = element.elements["url[@playback_scenario='FLASH_500K_512X288']"].text 24 | else 25 | @res_500_url = nil 26 | end 27 | if element.elements["url[@playback_scenario='FLASH_800K_640X360']"] 28 | @res_800_url = element.elements["url[@playback_scenario='FLASH_800K_640X360']"].text 29 | else 30 | @res_800_url = nil 31 | end 32 | end 33 | 34 | 35 | end 36 | end -------------------------------------------------------------------------------- /doc/classes/Game.src/M000212.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 394 14 | def get_attendance 15 | game_info = get_boxscore.game_info 16 | # parse game_info to get attendance 17 | game_info[game_info.length-12..game_info.length-7] 18 | end19 | 20 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000234.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 20 14 | def self.fetch_scoreboard(year, month, day) 15 | path = GamedayPathBuilder.build_scoreboard_path(year, month, day) 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000071.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 40 14 | def self.fetch_bench(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/bench.xml' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000072.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 50 14 | def self.fetch_bencho(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/benchO.xml' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000083.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 160 14 | def self.fetch_plays(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/plays.xml' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/Schedule.src/M000134.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/schedule.rb, line 32 14 | def get_sked_filename(year) 15 | #'schedules/' + year.to_s + 'SKED.TXT' 16 | File.expand_path(File.dirname(__FILE__) + '/schedules/' + year.to_s + 'SKED.TXT') 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/Game.src/M000217.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 450 14 | def get_num_innings 15 | bs = get_boxscore 16 | if bs.linescore 17 | return get_boxscore.linescore.innings.length 18 | else 19 | return 0 20 | end 21 | end22 | 23 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000235.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 26 14 | def self.fetch_day_highlights(year, month, day) 15 | path = GamedayPathBuilder.build_day_highlights_path(year, month, day) 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000261.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 222 14 | def self.fetch_notifications_inning(gid, inning) 15 | path = GamedayPathBuilder.build_game_base_path(gid) + "/notifications/notifications_#{inning}.xml" 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000090.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 227 14 | def self.fetch_batters_page(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/batters/' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000091.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 236 14 | def self.fetch_pitchers_page(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/pitchers/' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000074.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 71 14 | def self.fetch_emailsource(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/emailSource.xml' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000079.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 119 14 | def self.fetch_gamedaysyn(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/gameday_Syn.xml' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000093.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 252 14 | def self.fetch_media_mobile(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/media/mobile.xml' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000095.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 268 14 | def self.fetch_onbase_plays(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/onbase/plays.xml' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/PitchingAppearance.src/M000153.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/pitching_appearance.rb, line 41 14 | def quality_start? 15 | if @inn.to_i >= 6 && @r.to_i < 4 16 | return true 17 | end 18 | return false 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000081.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 140 14 | def self.fetch_miniscoreboard(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/miniscoreboard.xml' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/Gameday.src/M000265.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday.rb, line 47 14 | def convert_to_two_digit_str(number) 15 | if number < 10 16 | return '0'+number.to_s 17 | else 18 | return number.to_s 19 | end 20 | end21 | 22 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000092.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 244 14 | def self.fetch_media_highlights(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/media/highlights.xml' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000094.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 260 14 | def self.fetch_onbase_linescore(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + '/onbase/linescore.xml' 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000097.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 284 14 | def self.fetch_notifications_full(gid) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + "/notifications/notifications_full.xml" 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/Game.src/M000210.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 371 14 | def get_winner 15 | ls = get_boxscore.linescore 16 | if ls.home_team_runs > ls.away_team_runs 17 | return home_team_abbrev 18 | else 19 | return visit_team_abbrev 20 | end 21 | end22 | 23 | -------------------------------------------------------------------------------- /doc/classes/Pitcher.src/M000161.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/pitcher.rb, line 59 14 | def get_pitches 15 | results = [] 16 | ab = get_vs_ab 17 | ab.each do |ab| 18 | results << ab.pitches 19 | end 20 | results.flatten 21 | end22 | 23 | -------------------------------------------------------------------------------- /doc/classes/GamedayLocalFetcher.src/M000254.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_local_fetcher.rb, line 178 14 | def self.fetch_games_page(year, month, day) 15 | path = GamedayPathBuilder.build_day_path(year, month, day) + '/games.html' 16 | GamedayUtil.read_file(path) 17 | end18 | 19 | -------------------------------------------------------------------------------- /doc/classes/GamedayUtil.src/M000137.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_util.rb, line 21 14 | def self.convert_digit_to_string(digit) 15 | if digit<10 16 | return '0' + digit.to_s 17 | else 18 | return digit.to_s 19 | end 20 | end21 | 22 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000089.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 218 14 | def self.fetch_games_page(year, month, day) 15 | url = GamedayUrlBuilder.build_day_url(year, month, day) 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/Team.src/M000174.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/team.rb, line 165 14 | def get_leadoff_hitters_unique(year) 15 | hitters = get_leadoff_hitters_by_year(year) 16 | h = {} 17 | hitters.each {|hitter| h[hitter.batter_name]=hitter} 18 | h.values 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/Team.src/M000176.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/team.rb, line 192 14 | def get_cleanup_hitters_unique(year) 15 | hitters = get_cleanup_hitters_by_year(year) 16 | h = {} 17 | hitters.each {|hitter| h[hitter.batter_name]=hitter} 18 | h.values 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/Team.src/M000178.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/team.rb, line 216 14 | def get_starters_unique(year) 15 | pitchers = get_start_pitcher_appearances_by_year(year) 16 | h = {} 17 | pitchers.each {|pitcher| h[pitcher.pitcher_name]=pitcher} 18 | h.values 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/Team.src/M000180.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/team.rb, line 240 14 | def get_closers_unique(year) 15 | pitchers = get_close_pitcher_appearances_by_year(year) 16 | h = {} 17 | pitchers.each {|pitcher| h[pitcher.pitcher_name]=pitcher} 18 | h.values 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/GamedayRemoteFetcher.src/M000096.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_remote_fetcher.rb, line 276 14 | def self.fetch_notifications_inning(gid, inning) 15 | url = GamedayUrlBuilder.build_game_base_url(gid) + "/notifications/notifications_#{inning}.xml" 16 | fetch(url) 17 | #fetcher = CacheFetcher.new() 18 | #return fetcher.fetch(url) 19 | end20 | 21 | -------------------------------------------------------------------------------- /doc/classes/PitchingAppearance.src/M000155.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/pitching_appearance.rb, line 63 14 | def get_pitches 15 | results = [] 16 | ab = get_vs_ab 17 | ab.each do |ab| 18 | results << ab.pitches 19 | end 20 | results.flatten 21 | end22 | 23 | -------------------------------------------------------------------------------- /doc/classes/Roster.src/M000124.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/roster.rb, line 34 14 | def find_player_by_id(pid) 15 | players.each do |player| 16 | if player.pid == pid 17 | return player 18 | end 19 | end 20 | nil 21 | end22 | 23 | -------------------------------------------------------------------------------- /doc/classes/Game.src/M000201.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 256 14 | def dump_boxscore 15 | if self.gid 16 | bs = get_boxscore 17 | GamedayUtil.save_file("boxscore.html", bs.to_html('boxscore.html.erb')) 18 | else 19 | puts "No data for input specified" 20 | end 21 | end22 | 23 | -------------------------------------------------------------------------------- /doc/classes/GamedayUtil.src/M000139.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/gameday_util.rb, line 44 14 | def self.read_config 15 | settings = YAML::load_file(File.expand_path(File.dirname(__FILE__) + "/gameday_config.yml")) 16 | #settings = YAML::load_file(File.expand_path('gameday_config.yml')) 17 | set_proxy_info(settings) 18 | end19 | 20 | -------------------------------------------------------------------------------- /doc/classes/Roster.src/M000123.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/roster.rb, line 24 14 | def find_player_by_last_name(last_name) 15 | players.each do |player| 16 | if player.last == last_name 17 | return player 18 | end 19 | end 20 | nil 21 | end22 | 23 | -------------------------------------------------------------------------------- /doc/classes/BattingAppearance.src/M000219.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/batting_appearance.rb, line 39 14 | def get_player 15 | if !self.player 16 | # retrieve player object 17 | player = Player.new 18 | player.init() 19 | self.player = player 20 | end 21 | self.player 22 | end23 | 24 | -------------------------------------------------------------------------------- /doc/classes/Game.src/M000198.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 225 14 | def get_rosters 15 | if !self.rosters 16 | players = Players.new 17 | players.load_from_id(self.gid) 18 | self.rosters = players.rosters 19 | end 20 | self.rosters 21 | end22 | 23 | -------------------------------------------------------------------------------- /doc/classes/Roster.src/M000126.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/roster.rb, line 53 14 | def set_coaches(element) 15 | element.elements.each("coach") { |element| 16 | coach = Coach.new 17 | coach.init(element) 18 | self.coaches << coach 19 | } 20 | end21 | 22 | -------------------------------------------------------------------------------- /doc/classes/Game.src/M000192.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/game.rb, line 126 14 | def set_innings(element) 15 | element.elements.each("linescore/inning") { |element| 16 | @away_innings << element.attributes['away'] 17 | @home_innings << element.attributes['home'] 18 | } 19 | end20 | 21 | -------------------------------------------------------------------------------- /test/unit_tests/test_player.rb: -------------------------------------------------------------------------------- 1 | $: << File.expand_path(File.dirname(__FILE__) + "/../../lib") 2 | 3 | require 'test/unit' 4 | require 'player' 5 | 6 | class TestPlayer < Test::Unit::TestCase 7 | 8 | 9 | def test_load_from_id 10 | player = Player.new 11 | player.load_from_id('2009_09_20_detmlb_minmlb_1', '434158') 12 | 13 | assert player.gid == '2009_09_20_detmlb_minmlb_1' 14 | assert player.pid == '434158' 15 | assert player.first == 'Curtis' 16 | assert player.last == 'Granderson' 17 | assert player.num == '28' 18 | assert player.boxname == 'Granderson' 19 | assert player.rl == 'R' 20 | assert player.position == 'CF' 21 | assert player.status == 'A' 22 | assert player.bat_order == '1' 23 | assert player.game_position == 'CF' 24 | assert player.avg == '.250' 25 | assert player.hr == '27' 26 | assert player.rbi == '63' 27 | assert player.wins == nil 28 | assert player.losses == nil 29 | assert player.era == nil 30 | 31 | assert player.team == 'det' 32 | assert player.type == 'batter' 33 | assert player.height == '6-1' 34 | assert player.weight == '185' 35 | assert player.bats == 'L' 36 | assert player.throws == 'R' 37 | assert player.dob == '03/16/1981' 38 | end 39 | 40 | 41 | def test_get_team 42 | player = Player.new 43 | player.load_from_id('2009_09_20_detmlb_minmlb_1', '434158') 44 | team = player.get_team 45 | assert_not_nil team 46 | assert team.city == 'Detroit' 47 | assert team.name == 'Tigers' 48 | end 49 | 50 | 51 | end -------------------------------------------------------------------------------- /lib/gameday_api/inning.rb: -------------------------------------------------------------------------------- 1 | require 'gameday_api/at_bat' 2 | require 'gameday_api/gameday_fetcher' 3 | 4 | module GamedayApi 5 | 6 | # This class represents a single inning of an MLB game 7 | class Inning 8 | 9 | attr_accessor :gid, :num, :away_team, :home_team, :top_atbats, :bottom_atbats 10 | 11 | 12 | # loads an Inning object given a game id and an inning number 13 | def load_from_id(gid, inning) 14 | @top_atbats = [] 15 | @bottom_atbats = [] 16 | @gid = gid 17 | begin 18 | @xml_data = GamedayFetcher.fetch_inningx(gid, inning) 19 | @xml_doc = REXML::Document.new(@xml_data) 20 | if @xml_doc.root 21 | @num = @xml_doc.root.attributes["num"] 22 | @away_team = @xml_doc.root.attributes["away_team"] 23 | @home_team = @xml_doc.root.attributes["home_team"] 24 | set_top_ab 25 | set_bottom_ab 26 | end 27 | rescue 28 | puts "Could not load inning file for #{gid}, inning #{inning.to_s}" 29 | end 30 | end 31 | 32 | 33 | private 34 | 35 | def set_top_ab 36 | @xml_doc.elements.each("inning/top/atbat") { |element| 37 | atbat = AtBat.new 38 | atbat.init(element, @gid, @num) 39 | @top_atbats.push atbat 40 | } 41 | end 42 | 43 | 44 | def set_bottom_ab 45 | @xml_doc.elements.each("inning/bottom/atbat") { |element| 46 | atbat = AtBat.new 47 | atbat.init(element, @gid, @num) 48 | @bottom_atbats.push atbat 49 | } 50 | end 51 | 52 | 53 | end 54 | end -------------------------------------------------------------------------------- /doc/classes/DataDownloader.src/M000099.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/data_downloader.rb, line 19 14 | def download_all_for_game(gid) 15 | download_xml_for_game(gid) 16 | download_batters_for_game(gid) 17 | download_inning_for_game(gid) 18 | download_media_for_game(gid) 19 | download_notification_for_game(gid) 20 | download_onbase_for_game(gid) 21 | download_pitchers_for_game(gid) 22 | end23 | 24 | -------------------------------------------------------------------------------- /doc/classes/Roster.src/M000125.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/roster.rb, line 44 14 | def set_players(element) 15 | element.elements.each("player") { |element| 16 | player = Player.new 17 | player.init(element, gid) 18 | self.players << player 19 | } 20 | end21 | 22 | -------------------------------------------------------------------------------- /doc/classes/DataDownloader.src/M000111.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |
# File lib/data_downloader.rb, line 186 14 | def tmp_fetch_pages_for_game(gid) 15 | write_file(get_gid_path(gid) + "/batters.html", GamedayFetcher.fetch_batters_page(gid)) 16 | write_file(get_gid_path(gid) + "/pitchers.html", GamedayFetcher.fetch_pitchers_page(gid)) 17 | end18 | 19 | --------------------------------------------------------------------------------