mlb_gameday 0.0.11 → 0.1.0

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.
@@ -1,22 +1,16 @@
1
1
  module MLBGameday
2
- class League
3
- def initialize(name, divisions)
4
- @name = name
5
- @divisions = divisions
6
- end
2
+ class League
3
+ attr_reader :name, :divisions
7
4
 
8
- def name
9
- @name
10
- end
5
+ def initialize(name, divisions)
6
+ @name = name
7
+ @divisions = divisions
8
+ end
11
9
 
12
- def divisions
13
- @divisions
14
- end
10
+ def division(name)
11
+ fail 'Invalid division' unless %i(East Central West).include?(name)
15
12
 
16
- def division(name)
17
- raise "Invalid division" if ![:East, :Central, :West].include?(name)
18
-
19
- @divisions[name]
20
- end
21
- end
13
+ @divisions[name]
14
+ end
15
+ end
22
16
  end
@@ -1,44 +1,35 @@
1
1
  module MLBGameday
2
- class Pitcher < Player
3
- def name
4
- xpath("//Player//@first_name") + " " + xpath("//Player//@last_name")
5
- end
6
-
7
- def era
8
- xpath("//Player/season/@era")
9
- end
10
-
11
- def wins
12
- xpath("//Player/season/@w")
13
- end
14
-
15
- def losses
16
- xpath("//Player/season/@l")
17
- end
18
-
19
- def innings
20
- xpath("//Player/season/@ip")
21
- end
22
-
23
- def saves
24
- xpath("//Player/season/@sv")
25
- end
26
-
27
- def whip
28
- xpath("//Player/season/@whip")
29
- end
30
-
31
- def strikeouts
32
- xpath("//Player/season/@so")
33
- end
34
-
35
- def walks
36
- xpath("//Player/season/@bb")
37
- end
38
-
39
- # Returns a Nokogiri::XML object
40
- def data
41
- @data
42
- end
43
- end
2
+ class Pitcher < Player
3
+ def era
4
+ @data.xpath('//Player/season/@era').text.to_f
5
+ end
6
+
7
+ def wins
8
+ @data.xpath('//Player/season/@w').text.to_i
9
+ end
10
+
11
+ def losses
12
+ @data.xpath('//Player/season/@l').text.to_i
13
+ end
14
+
15
+ def innings
16
+ @data.xpath('//Player/season/@ip').text.to_f
17
+ end
18
+
19
+ def saves
20
+ @data.xpath('//Player/season/@sv').text.to_i
21
+ end
22
+
23
+ def whip
24
+ @data.xpath('//Player/season/@whip').text.to_f
25
+ end
26
+
27
+ def strikeouts
28
+ @data.xpath('//Player/season/@so').text.to_i
29
+ end
30
+
31
+ def walks
32
+ @data.xpath('//Player/season/@bb').text.to_i
33
+ end
34
+ end
44
35
  end
@@ -1,19 +1,22 @@
1
1
  module MLBGameday
2
- class Player
3
- def initialize(api, id, data)
4
- @api = api
5
- @id = id
6
- @data = data
7
- end
2
+ class Player
3
+ attr_reader :id, :data
8
4
 
9
- def id
10
- @id
11
- end
5
+ def initialize(id:, xml:)
6
+ @id = id
7
+ @data = xml
8
+ end
12
9
 
13
- protected
10
+ def first_name
11
+ @data.xpath('//Player//@first_name').text
12
+ end
14
13
 
15
- def xpath(path)
16
- @data.xpath(path).first.value
17
- end
18
- end
14
+ def last_name
15
+ @data.xpath('//Player//@last_name').text
16
+ end
17
+
18
+ def name
19
+ "#{first_name} #{last_name}"
20
+ end
21
+ end
19
22
  end
@@ -1,41 +1,21 @@
1
1
  module MLBGameday
2
- class Team
3
- def initialize(opts = {})
4
- @name = opts[:name]
5
- @city = opts[:city]
6
- @league = opts[:league]
7
- @division = opts[:division]
8
- @names = opts[:names]
9
- @code = opts[:code]
10
- end
2
+ class Team
3
+ attr_reader :id, :name, :city, :league, :division, :names, :code, :file_code
11
4
 
12
- # So we don't get huge printouts
13
- def inspect
14
- %Q{#<MLBGameday::Team @name="#{@name}">}
15
- end
5
+ def initialize(opts = {})
6
+ @id = opts[:id]
7
+ @name = opts[:name]
8
+ @city = opts[:city]
9
+ @league = opts[:league]
10
+ @division = opts[:division]
11
+ @names = opts[:names]
12
+ @code = opts[:code]
13
+ @file_code = opts[:file_code]
14
+ end
16
15
 
17
- def name
18
- @name
19
- end
20
-
21
- def city
22
- @city
23
- end
24
-
25
- def league
26
- @league
27
- end
28
-
29
- def division
30
- @division
31
- end
32
-
33
- def names
34
- @names
35
- end
36
-
37
- def code
38
- @code
39
- end
40
- end
16
+ # So we don't get huge printouts
17
+ def inspect
18
+ %(#<MLBGameday::Team @name="#{@name}">)
19
+ end
20
+ end
41
21
  end
@@ -1,3 +1,3 @@
1
1
  module MLBGameday
2
- VERSION = "0.0.11"
2
+ VERSION = '0.1.0'
3
3
  end
data/mlb_gameday.gemspec CHANGED
@@ -4,24 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'mlb_gameday/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "mlb_gameday"
7
+ spec.name = 'mlb_gameday'
8
8
  spec.version = MLBGameday::VERSION
9
- spec.authors = ["Steven Hoffman"]
10
- spec.email = ["git@fustrate.com"]
11
- spec.description = %q{Access data about games and players from the official MLB Gameday API}
12
- spec.summary = %q{Fetches gameday data from the MLB Gameday API}
13
- spec.homepage = "http://github.com/fustrate/mlb_gameday"
14
- spec.license = "MIT"
9
+ spec.authors = ['Steven Hoffman']
10
+ spec.email = ['git@fustrate.com']
11
+ spec.description = 'Access data about games and players from the ' \
12
+ 'official MLB Gameday API'
13
+ spec.summary = %(Fetches gameday data from the MLB Gameday API)
14
+ spec.homepage = 'http://github.com/fustrate/mlb_gameday'
15
+ spec.license = 'MIT'
15
16
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
17
+ spec.files = `git ls-files`.split($RS)
18
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
20
+ spec.require_paths = %w(lib)
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
25
 
25
- spec.add_dependency "httparty"
26
- spec.add_dependency "nokogiri"
26
+ spec.add_dependency 'httparty', '~> 0.13'
27
+ spec.add_dependency 'nokogiri', '~> 1.6'
28
+ spec.add_dependency 'chronic', '~> 0.10'
27
29
  end
data/resources/data.yml CHANGED
@@ -5,6 +5,7 @@
5
5
  :East: &aleast !ruby/object:MLBGameday::Division
6
6
  name: East
7
7
  league: *al
8
+ id: 201
8
9
  teams:
9
10
  :BAL: !ruby/object:MLBGameday::Team
10
11
  name: Orioles
@@ -12,6 +13,8 @@
12
13
  league: *al
13
14
  division: *aleast
14
15
  code: BAL
16
+ file_code: bal
17
+ id: 110
15
18
  names:
16
19
  - bal
17
20
  - orioles
@@ -23,6 +26,8 @@
23
26
  league: *al
24
27
  division: *aleast
25
28
  code: BOS
29
+ file_code: bos
30
+ id: 111
26
31
  names:
27
32
  - bos
28
33
  - red sox
@@ -35,6 +40,8 @@
35
40
  league: *al
36
41
  division: *aleast
37
42
  code: NYY
43
+ file_code: nyy
44
+ id: 147
38
45
  names:
39
46
  - nyy
40
47
  - yankees
@@ -47,6 +54,8 @@
47
54
  league: *al
48
55
  division: *aleast
49
56
  code: TB
57
+ file_code: tb
58
+ id: 139
50
59
  names:
51
60
  - tb
52
61
  - rays
@@ -61,6 +70,8 @@
61
70
  league: *al
62
71
  division: *aleast
63
72
  code: TOR
73
+ file_code: tor
74
+ id: 141
64
75
  names:
65
76
  - tor
66
77
  - blue jays
@@ -73,6 +84,7 @@
73
84
  :Central: &alcentral !ruby/object:MLBGameday::Division
74
85
  name: Central
75
86
  league: *al
87
+ id: 202
76
88
  teams:
77
89
  :CLE: !ruby/object:MLBGameday::Team
78
90
  name: Indians
@@ -80,6 +92,8 @@
80
92
  league: *al
81
93
  division: *alcentral
82
94
  code: CLE
95
+ file_code: cle
96
+ id: 114
83
97
  names:
84
98
  - cle
85
99
  - indians
@@ -91,6 +105,8 @@
91
105
  league: *al
92
106
  division: *alcentral
93
107
  code: CWS
108
+ file_code: cws
109
+ id: 145
94
110
  names:
95
111
  - cws
96
112
  - white sox
@@ -101,6 +117,8 @@
101
117
  league: *al
102
118
  division: *alcentral
103
119
  code: DET
120
+ file_code: det
121
+ id: 116
104
122
  names:
105
123
  - det
106
124
  - tigers
@@ -112,6 +130,8 @@
112
130
  league: *al
113
131
  division: *alcentral
114
132
  code: KC
133
+ file_code: kc
134
+ id: 118
115
135
  names:
116
136
  - kc
117
137
  - royals
@@ -124,6 +144,8 @@
124
144
  league: *al
125
145
  division: *alcentral
126
146
  code: MIN
147
+ file_code: min
148
+ id: 142
127
149
  names:
128
150
  - min
129
151
  - twins
@@ -132,6 +154,7 @@
132
154
  :West: &alwest !ruby/object:MLBGameday::Division
133
155
  name: West
134
156
  league: *al
157
+ id: 200
135
158
  teams:
136
159
  :LAA: !ruby/object:MLBGameday::Team
137
160
  name: Angels
@@ -139,6 +162,8 @@
139
162
  league: *al
140
163
  division: *alwest
141
164
  code: LAA
165
+ file_code: ana
166
+ id: 108
142
167
  names:
143
168
  - ana
144
169
  - angels
@@ -158,6 +183,8 @@
158
183
  league: *al
159
184
  division: *alwest
160
185
  code: HOU
186
+ file_code: hou
187
+ id: 117
161
188
  names:
162
189
  - hou
163
190
  - astros
@@ -169,6 +196,8 @@
169
196
  league: *al
170
197
  division: *alwest
171
198
  code: OAK
199
+ file_code: oak
200
+ id: 133
172
201
  names:
173
202
  - oak
174
203
  - athletics
@@ -181,6 +210,8 @@
181
210
  league: *al
182
211
  division: *alwest
183
212
  code: SEA
213
+ file_code: sea
214
+ id: 136
184
215
  names:
185
216
  - sea
186
217
  - mariners
@@ -192,6 +223,8 @@
192
223
  league: *al
193
224
  division: *alwest
194
225
  code: TEX
226
+ file_code: tex
227
+ id: 140
195
228
  names:
196
229
  - tex
197
230
  - rangers
@@ -203,6 +236,7 @@
203
236
  :East: &nleast !ruby/object:MLBGameday::Division
204
237
  name: East
205
238
  league: *nl
239
+ id: 204
206
240
  teams:
207
241
  :ATL: !ruby/object:MLBGameday::Team
208
242
  name: Braves
@@ -210,6 +244,8 @@
210
244
  league: *nl
211
245
  division: *nleast
212
246
  code: ATL
247
+ file_code: atl
248
+ id: 144
213
249
  names:
214
250
  - atl
215
251
  - braves
@@ -221,6 +257,8 @@
221
257
  league: *nl
222
258
  division: *nleast
223
259
  code: MIA
260
+ file_code: mia
261
+ id: 146
224
262
  names:
225
263
  - mia
226
264
  - marlins
@@ -233,6 +271,8 @@
233
271
  league: *nl
234
272
  division: *nleast
235
273
  code: NYM
274
+ file_code: nym
275
+ id: 121
236
276
  names:
237
277
  - nym
238
278
  - mets
@@ -245,6 +285,8 @@
245
285
  league: *nl
246
286
  division: *nleast
247
287
  code: PHI
288
+ file_code: phi
289
+ id: 143
248
290
  names:
249
291
  - phi
250
292
  - phillies
@@ -257,6 +299,8 @@
257
299
  league: *nl
258
300
  division: *nleast
259
301
  code: WSH
302
+ file_code: wsh
303
+ id: 120
260
304
  names:
261
305
  - wsh
262
306
  - nationals
@@ -266,6 +310,7 @@
266
310
  :Central: &nlcentral !ruby/object:MLBGameday::Division
267
311
  name: Central
268
312
  league: *nl
313
+ id: 205
269
314
  teams:
270
315
  :CHC: !ruby/object:MLBGameday::Team
271
316
  name: Cubs
@@ -273,6 +318,8 @@
273
318
  league: *nl
274
319
  division: *nlcentral
275
320
  code: CHC
321
+ file_code: chc
322
+ id: 112
276
323
  names:
277
324
  - chc
278
325
  - cubs
@@ -285,6 +332,8 @@
285
332
  league: *nl
286
333
  division: *nlcentral
287
334
  code: CIN
335
+ file_code: cin
336
+ id: 113
288
337
  names:
289
338
  - cin
290
339
  - reds
@@ -296,6 +345,8 @@
296
345
  league: *nl
297
346
  division: *nlcentral
298
347
  code: MIL
348
+ file_code: mil
349
+ id: 158
299
350
  names:
300
351
  - mil
301
352
  - brewers
@@ -307,6 +358,8 @@
307
358
  league: *nl
308
359
  division: *nlcentral
309
360
  code: PIT
361
+ file_code: pit
362
+ id: 134
310
363
  names:
311
364
  - pit
312
365
  - pirates
@@ -320,6 +373,8 @@
320
373
  league: *nl
321
374
  division: *nlcentral
322
375
  code: STL
376
+ file_code: stl
377
+ id: 138
323
378
  names:
324
379
  - stl
325
380
  - cardinals
@@ -329,6 +384,7 @@
329
384
  :West: &nlwest !ruby/object:MLBGameday::Division
330
385
  name: West
331
386
  league: *nl
387
+ id: 203
332
388
  teams:
333
389
  :ARI: !ruby/object:MLBGameday::Team
334
390
  name: Diamondbacks
@@ -336,6 +392,8 @@
336
392
  league: *nl
337
393
  division: *nlwest
338
394
  code: ARI
395
+ file_code: ari
396
+ id: 109
339
397
  names:
340
398
  - ari
341
399
  - diamondbacks
@@ -350,6 +408,8 @@
350
408
  league: *nl
351
409
  division: *nlwest
352
410
  code: COL
411
+ file_code: col
412
+ id: 115
353
413
  names:
354
414
  - col
355
415
  - rockies
@@ -361,6 +421,8 @@
361
421
  league: *nl
362
422
  division: *nlwest
363
423
  code: LAD
424
+ file_code: la
425
+ id: 119
364
426
  names:
365
427
  - lad
366
428
  - dodgers
@@ -377,6 +439,8 @@
377
439
  league: *nl
378
440
  division: *nlwest
379
441
  code: SD
442
+ file_code: sd
443
+ id: 135
380
444
  names:
381
445
  - sd
382
446
  - padres
@@ -388,6 +452,8 @@
388
452
  league: *nl
389
453
  division: *nlwest
390
454
  code: SF
455
+ file_code: sf
456
+ id: 137
391
457
  names:
392
458
  - sf
393
459
  - giants