mlb_gameday 0.0.1.alpha1 → 0.0.1.alpha2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cdae658439dfe994e1f03e2e6c38169be5518fc4
4
- data.tar.gz: ad73fcb5ec67661ebd7e60273eb0e99ebeb37c8e
3
+ metadata.gz: 20b9c57b8372d771516dd33c460a2a371c480d40
4
+ data.tar.gz: cb8bedb141d799e2ace98bb3b0b2e1441b4a79aa
5
5
  SHA512:
6
- metadata.gz: 3c3f072edb92e46635ae7c47631503a11956747db40aaea8266f45f8e8f1e3e1d257babc7aa67d44f2303e4644231896c8fee72320a89d13f22be19860835167
7
- data.tar.gz: ca178b27d76e3d64122550e8f090a3722961bf9c995f719bc54b5745e2cfe56322cba75986350d9f62ca952348311b79602f08a17e9f66d2bc3647a5d75f82b5
6
+ metadata.gz: 9522000213ce1cd10565ac360acb4628f4ba396e91830d1f1811ef67e7a2d84a949eb7ce1cd79b09bc8e97907a50a143efd51b87e0675036f8cbb9561189a506
7
+ data.tar.gz: 3e9e3b8bd6208c3e03b7cb2ff51afdcfa6d0093d9dee758aaba551eef20b66488c0efb2d272baaa7321fb224c4a83fe84a0a5291a5a2483749d5d04b9a0f94ee
data/lib/mlb_gameday.rb CHANGED
@@ -62,8 +62,13 @@ module MLBGameday
62
62
 
63
63
  def game(gid)
64
64
  date = /\A(\d+)_(\d+)_(\d+)_/.match(gid)
65
+ date = DateTime.new(date[1].to_i, date[2].to_i, date[3].to_i)
65
66
 
66
- MLBGameday::Game.new(self, fetch_gameday_xml(DateTime.new(date[1].to_i, date[2].to_i, date[3].to_i), gid))
67
+ MLBGameday::Game.new(
68
+ self,
69
+ gamecenter: fetch_gamecenter_xml(date, gid),
70
+ linescore: fetch_linescore_xml(date, gid)
71
+ )
67
72
  end
68
73
 
69
74
  def find_games(team: nil, date: nil)
@@ -73,14 +78,26 @@ module MLBGameday
73
78
 
74
79
  if team.nil?
75
80
  doc.xpath("//games/game").map do |game|
76
- MLBGameday::Game.new(self, fetch_gameday_xml(date, game.xpath("@gameday_link").first.value))
81
+ gid = game.xpath("@gameday_link").first.value
82
+
83
+ MLBGameday::Game.new(
84
+ self,
85
+ gamecenter: fetch_gamecenter_xml(date, gid),
86
+ linescore: fetch_linescore_xml(date, gid)
87
+ )
77
88
  end
78
89
  else
79
90
  team = team(team)
80
91
 
81
92
  doc.xpath("//games/game").map do |game|
82
93
  if [game.xpath("@home_name_abbrev").first.value, game.xpath("@away_name_abbrev").first.value].include? team.code
83
- MLBGameday::Game.new(self, fetch_gameday_xml(date, game.xpath("@gameday_link")))
94
+ gid = game.xpath("@gameday_link").first.value
95
+
96
+ MLBGameday::Game.new(
97
+ self,
98
+ gamecenter: fetch_gamecenter_xml(date, gid),
99
+ linescore: fetch_linescore_xml(date, gid)
100
+ )
84
101
  end
85
102
  end.compact!
86
103
  end
@@ -92,10 +109,14 @@ module MLBGameday
92
109
  Nokogiri::XML(open(API_URL + date.strftime("/year_%Y/month_%m/day_%d/miniscoreboard.xml")))
93
110
  end
94
111
 
95
- def fetch_gameday_xml(date, gameday_link)
112
+ def fetch_linescore_xml(date, gameday_link)
96
113
  Nokogiri::XML(open(API_URL + date.strftime("/year_%Y/month_%m/day_%d/gid_#{ gameday_link }/linescore.xml")))
97
114
  end
98
115
 
116
+ def fetch_gamecenter_xml(date, gameday_link)
117
+ Nokogiri::XML(open(API_URL + date.strftime("/year_%Y/month_%m/day_%d/gid_#{ gameday_link }/gamecenter.xml")))
118
+ end
119
+
99
120
  def fetch_batter_xml(id, year: nil)
100
121
  year = Date.today.year if year.nil?
101
122
 
@@ -1,11 +1,12 @@
1
1
  module MLBGameday
2
2
  class Game
3
- def initialize(api, data)
3
+ def initialize(api, linescore: nil, gamecenter: nil)
4
4
  @api = api
5
- @data = data
5
+ @linescore = linescore
6
+ @gamecenter = gamecenter
6
7
 
7
- @home = @api.team(@data.xpath("//game/@home_name_abbrev").first.value)
8
- @away = @api.team(@data.xpath("//game/@away_name_abbrev").first.value)
8
+ @home = @api.team(@linescore.xpath("//game/@home_name_abbrev").first.value)
9
+ @away = @api.team(@linescore.xpath("//game/@away_name_abbrev").first.value)
9
10
  end
10
11
 
11
12
  def teams
@@ -21,23 +22,23 @@ module MLBGameday
21
22
  end
22
23
 
23
24
  def venue
24
- xpath("//game/@venue")
25
+ @linescore.xpath("//game/@venue").first.value
25
26
  end
26
27
 
27
28
  def start_time(team = nil)
28
- return "#{ xpath("//game/@away_time") } #{ xpath("//game/@away_time_zone") }" if team == @away
29
+ return "#{ @linescore.xpath("//game/@away_time").first.value } #{ @linescore.xpath("//game/@away_time_zone").first.value }" if team == @away
29
30
 
30
- "#{ xpath("//game/@home_time") } #{ xpath("//game/@home_time_zone") }"
31
+ "#{ @linescore.xpath("//game/@home_time").first.value } #{ @linescore.xpath("//game/@home_time_zone").first.value }"
31
32
  end
32
33
 
33
34
  # Preview, Pre-Game, In Progress, Final
34
35
  def status
35
- @status ||= @data.xpath("//game/@status").first.value
36
+ @status ||= @linescore.xpath("//game/@status").first.value
36
37
  end
37
38
 
38
39
  # [3, Top/Middle/Bottom/End]
39
40
  def inning
40
- [@data.xpath("//game/@inning"), @data.xpath("//game/@inning_state")]
41
+ [@linescore.xpath("//game/@inning").first.value, @linescore.xpath("//game/@inning_state").first.value]
41
42
  end
42
43
 
43
44
  def runners
@@ -56,60 +57,60 @@ module MLBGameday
56
57
  end
57
58
 
58
59
  def home_record
59
- [xpath("//game/@home_win"), xpath("//game/@home_loss")].map(&:to_i)
60
+ [@linescore.xpath("//game/@home_win").first.value, @linescore.xpath("//game/@home_loss").first.value].map(&:to_i)
60
61
  end
61
62
 
62
63
  def away_record
63
- [xpath("//game/@away_win"), xpath("//game/@away_loss")].map(&:to_i)
64
+ [@linescore.xpath("//game/@away_win").first.value, @linescore.xpath("//game/@away_loss").first.value].map(&:to_i)
64
65
  end
65
66
 
66
67
  def current_pitcher
67
68
  return nil if !in_progress?
68
69
 
69
- @api.pitcher xpath("//game/current_pitcher/@id")
70
+ @api.pitcher @linescore.xpath("//game/current_pitcher/@id").first.value
70
71
  end
71
72
 
72
73
  def opposing_pitcher
73
74
  return nil if !in_progress?
74
75
 
75
- @api.pitcher xpath("//game/opposing_pitcher/@id")
76
+ @api.pitcher @linescore.xpath("//game/opposing_pitcher/@id").first.value
76
77
  end
77
78
 
78
79
  def winning_pitcher
79
80
  return nil if !over?
80
81
 
81
- @api.pitcher xpath("//game/winning_pitcher/@id")
82
+ @api.pitcher @linescore.xpath("//game/winning_pitcher/@id").first.value
82
83
  end
83
84
 
84
85
  def losing_pitcher
85
86
  return nil if !over?
86
87
 
87
- @api.pitcher xpath("//game/losing_pitcher/@id")
88
+ @api.pitcher @linescore.xpath("//game/losing_pitcher/@id").first.value
88
89
  end
89
90
 
90
91
  def save_pitcher
91
92
  return nil if !over?
92
93
 
93
- @api.pitcher xpath("//game/save_pitcher/@id")
94
+ @api.pitcher @linescore.xpath("//game/save_pitcher/@id").first.value
94
95
  end
95
96
 
96
97
  def score
97
98
  return [0, 0] if !in_progress? && !over?
98
99
 
99
- [xpath("//game/@home_team_runs"), xpath("//game/@away_team_runs")].map(&:to_i)
100
+ [@linescore.xpath("//game/@home_team_runs").first.value, @linescore.xpath("//game/@away_team_runs").first.value].map(&:to_i)
100
101
  end
101
102
 
102
103
  def home_pitcher
103
104
  case status
104
105
  when "In Progress"
105
106
  # The xpath changes based on which half of the inning it is
106
- if xpath("//game/@top_inning") == "Y"
107
+ if @linescore.xpath("//game/@top_inning").first.value == "Y"
107
108
  opposing_pitcher
108
109
  else
109
110
  current_pitcher
110
111
  end
111
112
  when "Preview", "Warmup", "Pre-Game"
112
- @api.pitcher xpath("//game/home_probable_pitcher/@id")
113
+ @api.pitcher @linescore.xpath("//game/home_probable_pitcher/@id").first.value
113
114
  when "Final"
114
115
  home, away = score
115
116
 
@@ -131,13 +132,13 @@ module MLBGameday
131
132
  case status
132
133
  when "In Progress"
133
134
  # The xpath changes based on which half of the inning it is
134
- if xpath("//game/@top_inning") == "Y"
135
+ if @linescore.xpath("//game/@top_inning").first.value == "Y"
135
136
  current_pitcher
136
137
  else
137
138
  opposing_pitcher
138
139
  end
139
140
  when "Preview", "Warmup", "Pre-Game"
140
- @api.pitcher xpath("//game/away_probable_pitcher/@id")
141
+ @api.pitcher @linescore.xpath("//game/away_probable_pitcher/@id").first.value
141
142
  when "Final"
142
143
  home, away = score
143
144
 
@@ -155,10 +156,20 @@ module MLBGameday
155
156
  end
156
157
  end
157
158
 
158
- private
159
+ def home_tv
160
+ @gamecenter.xpath("//game/broadcast/home/tv").first.content
161
+ end
162
+
163
+ def away_tv
164
+ @gamecenter.xpath("//game/broadcast/away/tv").first.content
165
+ end
166
+
167
+ def home_radio
168
+ @gamecenter.xpath("//game/broadcast/home/radio").first.content
169
+ end
159
170
 
160
- def xpath(path)
161
- @data.xpath(path).first.value
171
+ def away_radio
172
+ @gamecenter.xpath("//game/broadcast/away/radio").first.content
162
173
  end
163
174
  end
164
175
  end
@@ -1,3 +1,3 @@
1
1
  module MLBGameday
2
- VERSION = "0.0.1.alpha1"
2
+ VERSION = "0.0.1.alpha2"
3
3
  end
data/spec/game_spec.rb CHANGED
@@ -42,4 +42,16 @@ describe "An MLB Gameday Game object" do
42
42
 
43
43
  expect(game.home_pitcher.name).to eq("Clayton Kershaw")
44
44
  end
45
+
46
+ it "should be on Prime Ticket and ESPN in Los Angeles" do
47
+ game = @games[0]
48
+
49
+ expect(game.home_tv).to eq("PRIME, ESPN")
50
+ end
51
+
52
+ it "should be on KNBR 680 in San Francisco" do
53
+ game = @games[0]
54
+
55
+ expect(game.away_radio).to eq("KNBR 680")
56
+ end
45
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mlb_gameday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha1
4
+ version: 0.0.1.alpha2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Hoffman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-31 00:00:00.000000000 Z
11
+ date: 2013-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler