mlb_gameday 0.1.3 → 0.1.4
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 +4 -4
- data/README.md +2 -1
- data/lib/mlb_gameday.rb +6 -6
- data/lib/mlb_gameday/team.rb +38 -2
- data/lib/mlb_gameday/version.rb +1 -1
- data/resources/data.yml +17 -151
- data/test/api_spec.rb +56 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6299f9b1205eaae985a66b13126e039e155a65c0
|
4
|
+
data.tar.gz: a6e7728f34e670cf8622430443126ee51049ed0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d68b8ba4599172fd4a5778bf3b905a3ed9bfb7cb74159a112fe7b4810ade98c3e15dfe750662e028292d822b7c4d43df8a400e30c6f81f0e7f99e6d61c8485a
|
7
|
+
data.tar.gz: 696090f7753d5611090a935709c12d3263c6cb889fd1a23db33127057ac9734d6b1eb0c82801308a909c34252c83e061ffe20c607311c57c78f89deaa3c66ed0
|
data/README.md
CHANGED
data/lib/mlb_gameday.rb
CHANGED
@@ -34,13 +34,11 @@ module MLBGameday
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def team(name)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
if name.is_a? MLBGameday::Team
|
38
|
+
name
|
39
|
+
else
|
40
|
+
teams.select { |team| team.is_called?(name) }.first
|
41
41
|
end
|
42
|
-
|
43
|
-
nil
|
44
42
|
end
|
45
43
|
|
46
44
|
def teams
|
@@ -149,6 +147,8 @@ module MLBGameday
|
|
149
147
|
|
150
148
|
def fetch_xml(path, interpolations = {})
|
151
149
|
Nokogiri::XML open format(API_URL + path + '.xml', interpolations)
|
150
|
+
rescue OpenURI::HTTPError
|
151
|
+
{}
|
152
152
|
end
|
153
153
|
end
|
154
154
|
end
|
data/lib/mlb_gameday/team.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module MLBGameday
|
2
2
|
class Team
|
3
|
-
attr_reader :id, :name, :city, :league, :division, :
|
3
|
+
attr_reader :id, :name, :city, :league, :division, :code, :file_code
|
4
4
|
|
5
5
|
def initialize(opts = {})
|
6
6
|
@id = opts[:id]
|
@@ -8,14 +8,50 @@ module MLBGameday
|
|
8
8
|
@city = opts[:city]
|
9
9
|
@league = opts[:league]
|
10
10
|
@division = opts[:division]
|
11
|
-
@
|
11
|
+
@alt_names = opts[:alt_names]
|
12
12
|
@code = opts[:code]
|
13
13
|
@file_code = opts[:file_code]
|
14
14
|
end
|
15
|
+
|
16
|
+
def full_name
|
17
|
+
"#{city} #{name}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def names
|
21
|
+
@names ||= (implicit_names + alt_names).uniq
|
22
|
+
end
|
23
|
+
|
24
|
+
def is_called?(name)
|
25
|
+
names.include?(name.downcase)
|
26
|
+
end
|
15
27
|
|
16
28
|
# So we don't get huge printouts
|
17
29
|
def inspect
|
18
30
|
%(#<MLBGameday::Team @name="#{@name}">)
|
19
31
|
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def alt_names
|
35
|
+
@alt_names ||= []
|
36
|
+
end
|
37
|
+
|
38
|
+
def implicit_names
|
39
|
+
result = strict_names + [code, singular_name, despaced_name].map(&:downcase)
|
40
|
+
result << city.downcase unless ["New York", "Chicago"].include?(city)
|
41
|
+
|
42
|
+
result.uniq
|
43
|
+
end
|
44
|
+
|
45
|
+
def strict_names
|
46
|
+
[name, full_name].map(&:downcase)
|
47
|
+
end
|
48
|
+
|
49
|
+
def singular_name
|
50
|
+
name.chomp('s')
|
51
|
+
end
|
52
|
+
|
53
|
+
def despaced_name
|
54
|
+
name.tr(' ', '')
|
55
|
+
end
|
20
56
|
end
|
21
57
|
end
|
data/lib/mlb_gameday/version.rb
CHANGED
data/resources/data.yml
CHANGED
@@ -15,11 +15,6 @@
|
|
15
15
|
code: BAL
|
16
16
|
file_code: bal
|
17
17
|
id: 110
|
18
|
-
names:
|
19
|
-
- bal
|
20
|
-
- orioles
|
21
|
-
- oriole
|
22
|
-
- baltimore
|
23
18
|
:BOS: !ruby/object:MLBGameday::Team
|
24
19
|
name: Red Sox
|
25
20
|
city: Boston
|
@@ -28,11 +23,7 @@
|
|
28
23
|
code: BOS
|
29
24
|
file_code: bos
|
30
25
|
id: 111
|
31
|
-
|
32
|
-
- bos
|
33
|
-
- red sox
|
34
|
-
- redsox
|
35
|
-
- boston
|
26
|
+
alt_names:
|
36
27
|
- bosox
|
37
28
|
:NYY: !ruby/object:MLBGameday::Team
|
38
29
|
name: Yankees
|
@@ -42,11 +33,7 @@
|
|
42
33
|
code: NYY
|
43
34
|
file_code: nyy
|
44
35
|
id: 147
|
45
|
-
|
46
|
-
- nyy
|
47
|
-
- yankees
|
48
|
-
- yankee
|
49
|
-
- new york yankees
|
36
|
+
alt_names:
|
50
37
|
- new york yankee
|
51
38
|
:TB: !ruby/object:MLBGameday::Team
|
52
39
|
name: Rays
|
@@ -56,14 +43,10 @@
|
|
56
43
|
code: TB
|
57
44
|
file_code: tb
|
58
45
|
id: 139
|
59
|
-
|
60
|
-
- tb
|
61
|
-
- rays
|
62
|
-
- ray
|
46
|
+
alt_names:
|
63
47
|
- devil rays
|
64
48
|
- devil ray
|
65
49
|
- tampa
|
66
|
-
- tampa bay
|
67
50
|
:TOR: !ruby/object:MLBGameday::Team
|
68
51
|
name: Blue Jays
|
69
52
|
city: Toronto
|
@@ -72,15 +55,10 @@
|
|
72
55
|
code: TOR
|
73
56
|
file_code: tor
|
74
57
|
id: 141
|
75
|
-
|
76
|
-
- tor
|
77
|
-
- blue jays
|
78
|
-
- blue jay
|
79
|
-
- bluejays
|
58
|
+
alt_names:
|
80
59
|
- bluejay
|
81
60
|
- jays
|
82
61
|
- jay
|
83
|
-
- toronto
|
84
62
|
:Central: &alcentral !ruby/object:MLBGameday::Division
|
85
63
|
name: Central
|
86
64
|
league: *al
|
@@ -94,11 +72,6 @@
|
|
94
72
|
code: CLE
|
95
73
|
file_code: cle
|
96
74
|
id: 114
|
97
|
-
names:
|
98
|
-
- cle
|
99
|
-
- indians
|
100
|
-
- indian
|
101
|
-
- cleveland
|
102
75
|
:CWS: !ruby/object:MLBGameday::Team
|
103
76
|
name: White Sox
|
104
77
|
city: Chicago
|
@@ -107,10 +80,6 @@
|
|
107
80
|
code: CWS
|
108
81
|
file_code: cws
|
109
82
|
id: 145
|
110
|
-
names:
|
111
|
-
- cws
|
112
|
-
- white sox
|
113
|
-
- chicago white sox
|
114
83
|
:DET: !ruby/object:MLBGameday::Team
|
115
84
|
name: Tigers
|
116
85
|
city: Detroit
|
@@ -119,11 +88,6 @@
|
|
119
88
|
code: DET
|
120
89
|
file_code: det
|
121
90
|
id: 116
|
122
|
-
names:
|
123
|
-
- det
|
124
|
-
- tigers
|
125
|
-
- tiger
|
126
|
-
- detroit
|
127
91
|
:KC: !ruby/object:MLBGameday::Team
|
128
92
|
name: Royals
|
129
93
|
city: Kansas City
|
@@ -132,11 +96,7 @@
|
|
132
96
|
code: KC
|
133
97
|
file_code: kc
|
134
98
|
id: 118
|
135
|
-
|
136
|
-
- kc
|
137
|
-
- royals
|
138
|
-
- royal
|
139
|
-
- kansas city
|
99
|
+
alt_names:
|
140
100
|
- kansas
|
141
101
|
:MIN: !ruby/object:MLBGameday::Team
|
142
102
|
name: Twins
|
@@ -146,11 +106,6 @@
|
|
146
106
|
code: MIN
|
147
107
|
file_code: min
|
148
108
|
id: 142
|
149
|
-
names:
|
150
|
-
- min
|
151
|
-
- twins
|
152
|
-
- twin
|
153
|
-
- minnesota
|
154
109
|
:West: &alwest !ruby/object:MLBGameday::Division
|
155
110
|
name: West
|
156
111
|
league: *al
|
@@ -164,17 +119,12 @@
|
|
164
119
|
code: LAA
|
165
120
|
file_code: ana
|
166
121
|
id: 108
|
167
|
-
|
168
|
-
- ana
|
169
|
-
- angels
|
170
|
-
- angel
|
171
|
-
- anaheim
|
122
|
+
alt_names:
|
172
123
|
- ana
|
173
124
|
- los angeles angel
|
174
125
|
- los angeles angels
|
175
126
|
- la angels
|
176
127
|
- la angel
|
177
|
-
- laa
|
178
128
|
- laaa
|
179
129
|
- los angeles angels of anaheim
|
180
130
|
:HOU: !ruby/object:MLBGameday::Team
|
@@ -185,11 +135,6 @@
|
|
185
135
|
code: HOU
|
186
136
|
file_code: hou
|
187
137
|
id: 117
|
188
|
-
names:
|
189
|
-
- hou
|
190
|
-
- astros
|
191
|
-
- astro
|
192
|
-
- houston
|
193
138
|
:OAK: !ruby/object:MLBGameday::Team
|
194
139
|
name: Athletics
|
195
140
|
city: Oakland
|
@@ -198,12 +143,8 @@
|
|
198
143
|
code: OAK
|
199
144
|
file_code: oak
|
200
145
|
id: 133
|
201
|
-
|
202
|
-
- oak
|
203
|
-
- athletics
|
204
|
-
- athletic
|
146
|
+
alt_names:
|
205
147
|
- as
|
206
|
-
- oakland
|
207
148
|
:SEA: !ruby/object:MLBGameday::Team
|
208
149
|
name: Mariners
|
209
150
|
city: Seattle
|
@@ -212,11 +153,6 @@
|
|
212
153
|
code: SEA
|
213
154
|
file_code: sea
|
214
155
|
id: 136
|
215
|
-
names:
|
216
|
-
- sea
|
217
|
-
- mariners
|
218
|
-
- mariner
|
219
|
-
- seattle
|
220
156
|
:TEX: !ruby/object:MLBGameday::Team
|
221
157
|
name: Rangers
|
222
158
|
city: Texas
|
@@ -225,11 +161,6 @@
|
|
225
161
|
code: TEX
|
226
162
|
file_code: tex
|
227
163
|
id: 140
|
228
|
-
names:
|
229
|
-
- tex
|
230
|
-
- rangers
|
231
|
-
- ranger
|
232
|
-
- texas
|
233
164
|
:NL: &nl !ruby/object:MLBGameday::League
|
234
165
|
name: National
|
235
166
|
divisions:
|
@@ -246,11 +177,6 @@
|
|
246
177
|
code: ATL
|
247
178
|
file_code: atl
|
248
179
|
id: 144
|
249
|
-
names:
|
250
|
-
- atl
|
251
|
-
- braves
|
252
|
-
- brave
|
253
|
-
- atlanta
|
254
180
|
:MIA: !ruby/object:MLBGameday::Team
|
255
181
|
name: Marlins
|
256
182
|
city: Miami
|
@@ -259,11 +185,7 @@
|
|
259
185
|
code: MIA
|
260
186
|
file_code: mia
|
261
187
|
id: 146
|
262
|
-
|
263
|
-
- mia
|
264
|
-
- marlins
|
265
|
-
- marlin
|
266
|
-
- miami
|
188
|
+
alt_names:
|
267
189
|
- florida
|
268
190
|
:NYM: !ruby/object:MLBGameday::Team
|
269
191
|
name: Mets
|
@@ -273,11 +195,7 @@
|
|
273
195
|
code: NYM
|
274
196
|
file_code: nym
|
275
197
|
id: 121
|
276
|
-
|
277
|
-
- nym
|
278
|
-
- mets
|
279
|
-
- met
|
280
|
-
- new york mets
|
198
|
+
alt_names:
|
281
199
|
- new york met
|
282
200
|
:PHI: !ruby/object:MLBGameday::Team
|
283
201
|
name: Phillies
|
@@ -287,12 +205,8 @@
|
|
287
205
|
code: PHI
|
288
206
|
file_code: phi
|
289
207
|
id: 143
|
290
|
-
|
291
|
-
- phi
|
292
|
-
- phillies
|
293
|
-
- phillie
|
208
|
+
alt_names:
|
294
209
|
- philly
|
295
|
-
- philadelphia
|
296
210
|
:WSH: !ruby/object:MLBGameday::Team
|
297
211
|
name: Nationals
|
298
212
|
city: Washington
|
@@ -301,12 +215,8 @@
|
|
301
215
|
code: WSH
|
302
216
|
file_code: was
|
303
217
|
id: 120
|
304
|
-
|
305
|
-
- wsh
|
306
|
-
- nationals
|
218
|
+
alt_names:
|
307
219
|
- natinals
|
308
|
-
- national
|
309
|
-
- washington
|
310
220
|
:Central: &nlcentral !ruby/object:MLBGameday::Division
|
311
221
|
name: Central
|
312
222
|
league: *nl
|
@@ -320,11 +230,7 @@
|
|
320
230
|
code: CHC
|
321
231
|
file_code: chc
|
322
232
|
id: 112
|
323
|
-
|
324
|
-
- chc
|
325
|
-
- cubs
|
326
|
-
- cub
|
327
|
-
- chicago cubs
|
233
|
+
alt_names:
|
328
234
|
- chicago cub
|
329
235
|
:CIN: !ruby/object:MLBGameday::Team
|
330
236
|
name: Reds
|
@@ -334,11 +240,6 @@
|
|
334
240
|
code: CIN
|
335
241
|
file_code: cin
|
336
242
|
id: 113
|
337
|
-
names:
|
338
|
-
- cin
|
339
|
-
- reds
|
340
|
-
- red
|
341
|
-
- cincinnati
|
342
243
|
:MIL: !ruby/object:MLBGameday::Team
|
343
244
|
name: Brewers
|
344
245
|
city: Milwaukee
|
@@ -347,11 +248,6 @@
|
|
347
248
|
code: MIL
|
348
249
|
file_code: mil
|
349
250
|
id: 158
|
350
|
-
names:
|
351
|
-
- mil
|
352
|
-
- brewers
|
353
|
-
- brewer
|
354
|
-
- milwaukee
|
355
251
|
:PIT: !ruby/object:MLBGameday::Team
|
356
252
|
name: Pirates
|
357
253
|
city: Pittsburgh
|
@@ -360,13 +256,9 @@
|
|
360
256
|
code: PIT
|
361
257
|
file_code: pit
|
362
258
|
id: 134
|
363
|
-
|
364
|
-
- pit
|
365
|
-
- pirates
|
366
|
-
- pirate
|
259
|
+
alt_names:
|
367
260
|
- buccos
|
368
261
|
- bucco
|
369
|
-
- pittsburgh
|
370
262
|
:STL: !ruby/object:MLBGameday::Team
|
371
263
|
name: Cardinals
|
372
264
|
city: St. Louis
|
@@ -375,12 +267,8 @@
|
|
375
267
|
code: STL
|
376
268
|
file_code: stl
|
377
269
|
id: 138
|
378
|
-
|
379
|
-
- stl
|
380
|
-
- cardinals
|
381
|
-
- cardinal
|
270
|
+
alt_names:
|
382
271
|
- st louis
|
383
|
-
- st. louis
|
384
272
|
:West: &nlwest !ruby/object:MLBGameday::Division
|
385
273
|
name: West
|
386
274
|
league: *nl
|
@@ -394,13 +282,9 @@
|
|
394
282
|
code: ARI
|
395
283
|
file_code: ari
|
396
284
|
id: 109
|
397
|
-
|
398
|
-
- ari
|
399
|
-
- diamondbacks
|
400
|
-
- diamondback
|
285
|
+
alt_names:
|
401
286
|
- dbacks
|
402
287
|
- dback
|
403
|
-
- arizona
|
404
288
|
- az
|
405
289
|
:COL: !ruby/object:MLBGameday::Team
|
406
290
|
name: Rockies
|
@@ -410,11 +294,6 @@
|
|
410
294
|
code: COL
|
411
295
|
file_code: col
|
412
296
|
id: 115
|
413
|
-
names:
|
414
|
-
- col
|
415
|
-
- rockies
|
416
|
-
- rockie
|
417
|
-
- colorado
|
418
297
|
:LAD: !ruby/object:MLBGameday::Team
|
419
298
|
name: Dodgers
|
420
299
|
city: Los Angeles
|
@@ -423,11 +302,7 @@
|
|
423
302
|
code: LAD
|
424
303
|
file_code: la
|
425
304
|
id: 119
|
426
|
-
|
427
|
-
- lad
|
428
|
-
- dodgers
|
429
|
-
- dodger
|
430
|
-
- los angeles
|
305
|
+
alt_names:
|
431
306
|
- la
|
432
307
|
- los angeles dodgers
|
433
308
|
- los angeles dodger
|
@@ -441,11 +316,6 @@
|
|
441
316
|
code: SD
|
442
317
|
file_code: sd
|
443
318
|
id: 135
|
444
|
-
names:
|
445
|
-
- sd
|
446
|
-
- padres
|
447
|
-
- padre
|
448
|
-
- san diego
|
449
319
|
:SF: !ruby/object:MLBGameday::Team
|
450
320
|
name: Giants
|
451
321
|
city: San Francisco
|
@@ -454,10 +324,6 @@
|
|
454
324
|
code: SF
|
455
325
|
file_code: sf
|
456
326
|
id: 137
|
457
|
-
|
458
|
-
- sf
|
459
|
-
- giants
|
460
|
-
- giant
|
327
|
+
alt_names:
|
461
328
|
- san fran
|
462
|
-
- san francisco
|
463
329
|
- gigantes
|
data/test/api_spec.rb
CHANGED
@@ -30,6 +30,10 @@ class TestApi < MiniTest::Test
|
|
30
30
|
assert_equal @api.team('Dodgers').city, 'Los Angeles'
|
31
31
|
end
|
32
32
|
|
33
|
+
def test_name_search_for_nonexistent_returns_nil
|
34
|
+
assert_nil @api.team('Senators')
|
35
|
+
end
|
36
|
+
|
33
37
|
def test_division_team_count
|
34
38
|
assert_equal @api.team('Dodgers').division.teams.count, 5
|
35
39
|
end
|
@@ -38,4 +42,56 @@ class TestApi < MiniTest::Test
|
|
38
42
|
assert_equal @api.team('Astros').league.name, 'American'
|
39
43
|
assert_equal @api.team('Astros').division.name, 'West'
|
40
44
|
end
|
45
|
+
|
46
|
+
def test_names_includes_code
|
47
|
+
@api.teams.each do |team|
|
48
|
+
assert_includes team.names, team.code.downcase
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_names_includes_name
|
53
|
+
@api.teams.each do |team|
|
54
|
+
assert_includes team.names, team.name.downcase
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_names_includes_alt_names
|
59
|
+
@api.teams.each do |team|
|
60
|
+
team.send(:alt_names).each do |alt_name|
|
61
|
+
assert_includes team.names, alt_name.downcase
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_names_include_singular_name_when_different_from_name
|
67
|
+
@api.teams.reject {|team| team.name == team.send(:singular_name)}.each do |team|
|
68
|
+
assert_includes team.names, team.send(:singular_name).downcase
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_names_includes_despaced_name_when_name_is_multi_word
|
73
|
+
@api.teams.select {|team| team.name.split.size > 1}.each do |team|
|
74
|
+
assert_includes team.names, team.send(:despaced_name).downcase
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_names_includes_city_except_nyc_and_chicago
|
79
|
+
@api.teams.reject {|team| ["New York", "Chicago"].include?(team.city)}.each do |team|
|
80
|
+
assert_includes team.names, team.city.downcase
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_names_does_not_include_city_for_nyc_and_chicago
|
85
|
+
@api.teams.select {|team| ["New York", "Chicago"].include?(team.city)}.each do |team|
|
86
|
+
refute_includes team.names, team.city.downcase
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_no_teams_share_any_names
|
91
|
+
@api.teams.each do |team|
|
92
|
+
@api.teams.select {|t| t != team}.each do |other_team|
|
93
|
+
assert_equal (team.names - other_team.names), team.names
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
41
97
|
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.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Hoffman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
241
|
version: '0'
|
242
242
|
requirements: []
|
243
243
|
rubyforge_project:
|
244
|
-
rubygems_version: 2.
|
244
|
+
rubygems_version: 2.5.1
|
245
245
|
signing_key:
|
246
246
|
specification_version: 4
|
247
247
|
summary: Fetches gameday data from the MLB Gameday API
|