mlb 0.10.0 → 0.11.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.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +329 -108
  4. data/lib/mlb/affiliates.rb +28 -0
  5. data/lib/mlb/alumni.rb +30 -0
  6. data/lib/mlb/attendance.rb +28 -0
  7. data/lib/mlb/attendance_record.rb +157 -0
  8. data/lib/mlb/award.rb +89 -11
  9. data/lib/mlb/awards.rb +17 -7
  10. data/lib/mlb/baseball_stat.rb +65 -0
  11. data/lib/mlb/baseball_stats.rb +12 -0
  12. data/lib/mlb/boxscore.rb +81 -0
  13. data/lib/mlb/boxscore_team_stats.rb +210 -0
  14. data/lib/mlb/client.rb +71 -0
  15. data/lib/mlb/coaches.rb +28 -0
  16. data/lib/mlb/code_description_type.rb +45 -0
  17. data/lib/mlb/collection.rb +48 -0
  18. data/lib/mlb/comparable_by_attribute.rb +56 -0
  19. data/lib/mlb/conference.rb +8 -1
  20. data/lib/mlb/conferences.rb +18 -10
  21. data/lib/mlb/connection.rb +130 -7
  22. data/lib/mlb/context_metrics.rb +90 -0
  23. data/lib/mlb/division.rb +24 -6
  24. data/lib/mlb/divisions.rb +24 -18
  25. data/lib/mlb/draft.rb +83 -0
  26. data/lib/mlb/draft_pick.rb +155 -0
  27. data/lib/mlb/error_handler.rb +21 -1
  28. data/lib/mlb/errors/bad_gateway.rb +6 -1
  29. data/lib/mlb/errors/bad_request.rb +1 -0
  30. data/lib/mlb/errors/client_error.rb +1 -0
  31. data/lib/mlb/errors/connection_exception.rb +1 -0
  32. data/lib/mlb/errors/error.rb +1 -0
  33. data/lib/mlb/errors/forbidden.rb +1 -0
  34. data/lib/mlb/errors/gateway_timeout.rb +6 -1
  35. data/lib/mlb/errors/gone.rb +1 -0
  36. data/lib/mlb/errors/http_error.rb +22 -2
  37. data/lib/mlb/errors/internal_server_error.rb +1 -0
  38. data/lib/mlb/errors/network_error.rb +6 -1
  39. data/lib/mlb/errors/not_acceptable.rb +1 -0
  40. data/lib/mlb/errors/not_found.rb +1 -0
  41. data/lib/mlb/errors/payload_too_large.rb +1 -0
  42. data/lib/mlb/errors/retryable.rb +15 -0
  43. data/lib/mlb/errors/server_error.rb +1 -0
  44. data/lib/mlb/errors/service_unavailable.rb +6 -1
  45. data/lib/mlb/errors/too_many_redirects.rb +1 -0
  46. data/lib/mlb/errors/too_many_requests.rb +6 -1
  47. data/lib/mlb/errors/unauthorized.rb +1 -0
  48. data/lib/mlb/errors/unprocessable_entity.rb +1 -0
  49. data/lib/mlb/event_type.rb +61 -0
  50. data/lib/mlb/event_types.rb +12 -0
  51. data/lib/mlb/free_agent.rb +78 -0
  52. data/lib/mlb/free_agents.rb +34 -0
  53. data/lib/mlb/game_changes.rb +87 -0
  54. data/lib/mlb/game_content.rb +251 -0
  55. data/lib/mlb/game_data.rb +155 -0
  56. data/lib/mlb/game_pace.rb +173 -0
  57. data/lib/mlb/game_status.rb +94 -0
  58. data/lib/mlb/game_statuses.rb +12 -0
  59. data/lib/mlb/game_type.rb +98 -0
  60. data/lib/mlb/game_types.rb +12 -0
  61. data/lib/mlb/handedness.rb +28 -10
  62. data/lib/mlb/high_low.rb +121 -0
  63. data/lib/mlb/hit_trajectories.rb +12 -0
  64. data/lib/mlb/hit_trajectory.rb +6 -0
  65. data/lib/mlb/home_run_derby.rb +285 -0
  66. data/lib/mlb/id_description_type.rb +44 -0
  67. data/lib/mlb/inning_score.rb +87 -0
  68. data/lib/mlb/job.rb +58 -0
  69. data/lib/mlb/job_type.rb +39 -0
  70. data/lib/mlb/job_types.rb +12 -0
  71. data/lib/mlb/jobs.rb +87 -0
  72. data/lib/mlb/language.rb +48 -0
  73. data/lib/mlb/languages.rb +12 -0
  74. data/lib/mlb/leader.rb +79 -0
  75. data/lib/mlb/leaders.rb +68 -0
  76. data/lib/mlb/league.rb +95 -14
  77. data/lib/mlb/league_leader_type.rb +21 -0
  78. data/lib/mlb/league_leader_types.rb +12 -0
  79. data/lib/mlb/leagues.rb +24 -18
  80. data/lib/mlb/linescore.rb +342 -0
  81. data/lib/mlb/linescore_teams.rb +89 -0
  82. data/lib/mlb/live_feed.rb +130 -0
  83. data/lib/mlb/logical_event.rb +17 -0
  84. data/lib/mlb/logical_events.rb +12 -0
  85. data/lib/mlb/metric.rb +48 -0
  86. data/lib/mlb/metrics.rb +12 -0
  87. data/lib/mlb/people_changes.rb +34 -0
  88. data/lib/mlb/personnel.rb +28 -0
  89. data/lib/mlb/pitch_code.rb +90 -0
  90. data/lib/mlb/pitch_codes.rb +12 -0
  91. data/lib/mlb/pitch_type.rb +6 -0
  92. data/lib/mlb/pitch_types.rb +12 -0
  93. data/lib/mlb/platform.rb +30 -0
  94. data/lib/mlb/platforms.rb +12 -0
  95. data/lib/mlb/play.rb +300 -0
  96. data/lib/mlb/play_by_play.rb +52 -0
  97. data/lib/mlb/player.rb +182 -0
  98. data/lib/mlb/player_game_stats.rb +350 -0
  99. data/lib/mlb/player_stat.rb +70 -0
  100. data/lib/mlb/players.rb +34 -23
  101. data/lib/mlb/position.rb +65 -0
  102. data/lib/mlb/positions.rb +12 -0
  103. data/lib/mlb/postseason_schedule.rb +41 -0
  104. data/lib/mlb/postseason_series.rb +54 -0
  105. data/lib/mlb/redirect_handler.rb +80 -21
  106. data/lib/mlb/request_builder.rb +33 -2
  107. data/lib/mlb/review_reason.rb +6 -0
  108. data/lib/mlb/review_reasons.rb +12 -0
  109. data/lib/mlb/roster.rb +16 -12
  110. data/lib/mlb/roster_entry.rb +35 -0
  111. data/lib/mlb/roster_type.rb +39 -0
  112. data/lib/mlb/roster_types.rb +12 -0
  113. data/lib/mlb/schedule.rb +33 -0
  114. data/lib/mlb/schedule_date.rb +37 -0
  115. data/lib/mlb/schedule_event_type.rb +25 -0
  116. data/lib/mlb/schedule_event_types.rb +12 -0
  117. data/lib/mlb/scheduled_game.rb +321 -0
  118. data/lib/mlb/season.rb +15 -4
  119. data/lib/mlb/season_date_info.rb +1 -0
  120. data/lib/mlb/seasons.rb +24 -18
  121. data/lib/mlb/single_team_stats.rb +33 -0
  122. data/lib/mlb/situation_code.rb +116 -0
  123. data/lib/mlb/situation_codes.rb +12 -0
  124. data/lib/mlb/skies.rb +12 -0
  125. data/lib/mlb/sky.rb +3 -8
  126. data/lib/mlb/sport.rb +16 -5
  127. data/lib/mlb/sport_players.rb +30 -0
  128. data/lib/mlb/sports.rb +17 -7
  129. data/lib/mlb/standings.rb +47 -0
  130. data/lib/mlb/standings_record.rb +108 -0
  131. data/lib/mlb/standings_type.rb +25 -0
  132. data/lib/mlb/standings_types.rb +12 -0
  133. data/lib/mlb/stat_group.rb +21 -0
  134. data/lib/mlb/stat_groups.rb +12 -0
  135. data/lib/mlb/stat_type.rb +21 -0
  136. data/lib/mlb/stat_types.rb +12 -0
  137. data/lib/mlb/stat_values.rb +158 -0
  138. data/lib/mlb/stats.rb +41 -0
  139. data/lib/mlb/status.rb +14 -0
  140. data/lib/mlb/streaks.rb +184 -0
  141. data/lib/mlb/team.rb +62 -7
  142. data/lib/mlb/team_history.rb +28 -0
  143. data/lib/mlb/team_leader.rb +59 -0
  144. data/lib/mlb/team_leaders.rb +45 -0
  145. data/lib/mlb/team_record.rb +285 -0
  146. data/lib/mlb/team_stat.rb +50 -0
  147. data/lib/mlb/team_stats.rb +52 -0
  148. data/lib/mlb/teams.rb +28 -18
  149. data/lib/mlb/tied_games.rb +32 -0
  150. data/lib/mlb/transaction.rb +125 -0
  151. data/lib/mlb/transactions.rb +11 -6
  152. data/lib/mlb/uniforms.rb +97 -0
  153. data/lib/mlb/utils.rb +45 -0
  154. data/lib/mlb/venue.rb +7 -0
  155. data/lib/mlb/venues.rb +28 -18
  156. data/lib/mlb/version.rb +2 -1
  157. data/lib/mlb/win_probability.rb +64 -0
  158. data/lib/mlb/wind_direction.rb +3 -8
  159. data/lib/mlb/wind_directions.rb +12 -0
  160. data/lib/mlb.rb +61 -0
  161. data/sig/equalizer.rbs +3 -0
  162. data/sig/mlb.rbs +2055 -0
  163. data/sig/shale.rbs +29 -0
  164. metadata +107 -2
@@ -0,0 +1,342 @@
1
+ require "shale"
2
+ require_relative "inning_score"
3
+ require_relative "linescore_teams"
4
+
5
+ module MLB
6
+ # Represents a game's linescore
7
+ class Linescore < Shale::Mapper
8
+ INNING_TOP = "Top".freeze
9
+ INNING_MIDDLE = "Middle".freeze
10
+ INNING_BOTTOM = "Bottom".freeze
11
+
12
+ # @!attribute [rw] current_inning
13
+ # Returns the current inning number
14
+ # @api public
15
+ # @example
16
+ # linescore.current_inning #=> 9
17
+ # @return [Integer] the current inning
18
+ attribute :current_inning, Shale::Type::Integer
19
+
20
+ # @!attribute [rw] current_inning_ordinal
21
+ # Returns the current inning ordinal
22
+ # @api public
23
+ # @example
24
+ # linescore.current_inning_ordinal #=> "9th"
25
+ # @return [String] the current inning ordinal
26
+ attribute :current_inning_ordinal, Shale::Type::String
27
+
28
+ # @!attribute [rw] inning_state
29
+ # Returns the inning state (Top/Middle/Bottom/End)
30
+ # @api public
31
+ # @example
32
+ # linescore.inning_state #=> "Bottom"
33
+ # @return [String] the inning state
34
+ attribute :inning_state, Shale::Type::String
35
+
36
+ # @!attribute [rw] inning_half
37
+ # Returns the inning half
38
+ # @api public
39
+ # @example
40
+ # linescore.inning_half #=> "Bottom"
41
+ # @return [String] the inning half
42
+ attribute :inning_half, Shale::Type::String
43
+
44
+ # @!attribute [rw] is_top_inning
45
+ # Returns whether it's the top of the inning
46
+ # @api public
47
+ # @example
48
+ # linescore.top_inning? #=> false
49
+ # @return [Boolean] whether it's the top of the inning
50
+ attribute :is_top_inning, Shale::Type::Boolean
51
+
52
+ # @!attribute [rw] scheduled_innings
53
+ # Returns the number of scheduled innings
54
+ # @api public
55
+ # @example
56
+ # linescore.scheduled_innings #=> 9
57
+ # @return [Integer] the scheduled innings
58
+ attribute :scheduled_innings, Shale::Type::Integer
59
+
60
+ # @!attribute [rw] innings
61
+ # Returns the inning-by-inning scores
62
+ # @api public
63
+ # @example
64
+ # linescore.innings #=> [#<MLB::InningScore>, ...]
65
+ # @return [Array<InningScore>] the innings
66
+ attribute :innings, InningScore, collection: true
67
+
68
+ # @!attribute [rw] teams
69
+ # Returns the team totals
70
+ # @api public
71
+ # @example
72
+ # linescore.teams #=> #<MLB::LinescoreTeams>
73
+ # @return [LinescoreTeams] the teams
74
+ attribute :teams, LinescoreTeams
75
+
76
+ # Returns whether it's the top of the inning
77
+ #
78
+ # @api public
79
+ # @example
80
+ # linescore.top_inning? #=> false
81
+ # @return [Boolean] whether it's the top of the inning
82
+ def top_inning?
83
+ is_top_inning
84
+ end
85
+
86
+ # Returns whether the inning state is top
87
+ #
88
+ # @api public
89
+ # @example
90
+ # linescore.top? #=> true
91
+ # @return [Boolean] whether it's the top of the inning
92
+ def top? = inning_state.eql?(INNING_TOP)
93
+
94
+ # Returns whether the inning state is middle
95
+ #
96
+ # @api public
97
+ # @example
98
+ # linescore.middle? #=> false
99
+ # @return [Boolean] whether it's the middle of the inning
100
+ def middle? = inning_state.eql?(INNING_MIDDLE)
101
+
102
+ # Returns whether the inning state is bottom
103
+ #
104
+ # @api public
105
+ # @example
106
+ # linescore.bottom? #=> false
107
+ # @return [Boolean] whether it's the bottom of the inning
108
+ def bottom? = inning_state.eql?(INNING_BOTTOM)
109
+
110
+ # Returns whether it's the 1st inning
111
+ #
112
+ # @api public
113
+ # @example
114
+ # linescore.first? #=> true
115
+ # @return [Boolean] whether it's the 1st inning
116
+ def first? = current_inning.eql?(1)
117
+
118
+ # Returns whether it's the 2nd inning
119
+ #
120
+ # @api public
121
+ # @example
122
+ # linescore.second? #=> false
123
+ # @return [Boolean] whether it's the 2nd inning
124
+ def second? = current_inning.eql?(2)
125
+
126
+ # Returns whether it's the 3rd inning
127
+ #
128
+ # @api public
129
+ # @example
130
+ # linescore.third? #=> false
131
+ # @return [Boolean] whether it's the 3rd inning
132
+ def third? = current_inning.eql?(3)
133
+
134
+ # Returns whether it's the 4th inning
135
+ #
136
+ # @api public
137
+ # @example
138
+ # linescore.fourth? #=> false
139
+ # @return [Boolean] whether it's the 4th inning
140
+ def fourth? = current_inning.eql?(4)
141
+
142
+ # Returns whether it's the 5th inning
143
+ #
144
+ # @api public
145
+ # @example
146
+ # linescore.fifth? #=> false
147
+ # @return [Boolean] whether it's the 5th inning
148
+ def fifth? = current_inning.eql?(5)
149
+
150
+ # Returns whether it's the 6th inning
151
+ #
152
+ # @api public
153
+ # @example
154
+ # linescore.sixth? #=> false
155
+ # @return [Boolean] whether it's the 6th inning
156
+ def sixth? = current_inning.eql?(6)
157
+
158
+ # Returns whether it's the 7th inning
159
+ #
160
+ # @api public
161
+ # @example
162
+ # linescore.seventh? #=> false
163
+ # @return [Boolean] whether it's the 7th inning
164
+ def seventh? = current_inning.eql?(7)
165
+
166
+ # Returns whether it's the 8th inning
167
+ #
168
+ # @api public
169
+ # @example
170
+ # linescore.eighth? #=> false
171
+ # @return [Boolean] whether it's the 8th inning
172
+ def eighth? = current_inning.eql?(8)
173
+
174
+ # Returns whether it's the 9th inning
175
+ #
176
+ # @api public
177
+ # @example
178
+ # linescore.ninth? #=> false
179
+ # @return [Boolean] whether it's the 9th inning
180
+ def ninth? = current_inning.eql?(9)
181
+
182
+ # Returns whether it's the 10th inning
183
+ #
184
+ # @api public
185
+ # @example
186
+ # linescore.tenth? #=> false
187
+ # @return [Boolean] whether it's the 10th inning
188
+ def tenth? = current_inning.eql?(10)
189
+
190
+ # Returns whether it's the 11th inning
191
+ #
192
+ # @api public
193
+ # @example
194
+ # linescore.eleventh? #=> false
195
+ # @return [Boolean] whether it's the 11th inning
196
+ def eleventh? = current_inning.eql?(11)
197
+
198
+ # Returns whether it's the 12th inning
199
+ #
200
+ # @api public
201
+ # @example
202
+ # linescore.twelfth? #=> false
203
+ # @return [Boolean] whether it's the 12th inning
204
+ def twelfth? = current_inning.eql?(12)
205
+
206
+ # Returns whether it's the 13th inning
207
+ #
208
+ # @api public
209
+ # @example
210
+ # linescore.thirteenth? #=> false
211
+ # @return [Boolean] whether it's the 13th inning
212
+ def thirteenth? = current_inning.eql?(13)
213
+
214
+ # Returns whether it's the 14th inning
215
+ #
216
+ # @api public
217
+ # @example
218
+ # linescore.fourteenth? #=> false
219
+ # @return [Boolean] whether it's the 14th inning
220
+ def fourteenth? = current_inning.eql?(14)
221
+
222
+ # Returns whether it's the 15th inning
223
+ #
224
+ # @api public
225
+ # @example
226
+ # linescore.fifteenth? #=> false
227
+ # @return [Boolean] whether it's the 15th inning
228
+ def fifteenth? = current_inning.eql?(15)
229
+
230
+ # Returns whether it's the 16th inning
231
+ #
232
+ # @api public
233
+ # @example
234
+ # linescore.sixteenth? #=> false
235
+ # @return [Boolean] whether it's the 16th inning
236
+ def sixteenth? = current_inning.eql?(16)
237
+
238
+ # Returns whether it's the 17th inning
239
+ #
240
+ # @api public
241
+ # @example
242
+ # linescore.seventeenth? #=> false
243
+ # @return [Boolean] whether it's the 17th inning
244
+ def seventeenth? = current_inning.eql?(17)
245
+
246
+ # Returns whether it's the 18th inning
247
+ #
248
+ # @api public
249
+ # @example
250
+ # linescore.eighteenth? #=> false
251
+ # @return [Boolean] whether it's the 18th inning
252
+ def eighteenth? = current_inning.eql?(18)
253
+
254
+ # Returns whether it's the 19th inning
255
+ #
256
+ # @api public
257
+ # @example
258
+ # linescore.nineteenth? #=> false
259
+ # @return [Boolean] whether it's the 19th inning
260
+ def nineteenth? = current_inning.eql?(19)
261
+
262
+ # Returns whether it's the 20th inning
263
+ #
264
+ # @api public
265
+ # @example
266
+ # linescore.twentieth? #=> false
267
+ # @return [Boolean] whether it's the 20th inning
268
+ def twentieth? = current_inning.eql?(20)
269
+
270
+ # Returns whether it's the 21st inning
271
+ #
272
+ # @api public
273
+ # @example
274
+ # linescore.twenty_first? #=> false
275
+ # @return [Boolean] whether it's the 21st inning
276
+ def twenty_first? = current_inning.eql?(21)
277
+
278
+ # Returns whether it's the 22nd inning
279
+ #
280
+ # @api public
281
+ # @example
282
+ # linescore.twenty_second? #=> false
283
+ # @return [Boolean] whether it's the 22nd inning
284
+ def twenty_second? = current_inning.eql?(22)
285
+
286
+ # Returns whether it's the 23rd inning
287
+ #
288
+ # @api public
289
+ # @example
290
+ # linescore.twenty_third? #=> false
291
+ # @return [Boolean] whether it's the 23rd inning
292
+ def twenty_third? = current_inning.eql?(23)
293
+
294
+ # Returns whether it's the 24th inning
295
+ #
296
+ # @api public
297
+ # @example
298
+ # linescore.twenty_fourth? #=> false
299
+ # @return [Boolean] whether it's the 24th inning
300
+ def twenty_fourth? = current_inning.eql?(24)
301
+
302
+ # Returns whether it's the 25th inning
303
+ #
304
+ # @api public
305
+ # @example
306
+ # linescore.twenty_fifth? #=> false
307
+ # @return [Boolean] whether it's the 25th inning
308
+ def twenty_fifth? = current_inning.eql?(25)
309
+
310
+ # Returns whether it's the 26th inning
311
+ #
312
+ # @api public
313
+ # @example
314
+ # linescore.twenty_sixth? #=> false
315
+ # @return [Boolean] whether it's the 26th inning
316
+ def twenty_sixth? = current_inning.eql?(26)
317
+
318
+ json do
319
+ map "currentInning", to: :current_inning
320
+ map "currentInningOrdinal", to: :current_inning_ordinal
321
+ map "inningState", to: :inning_state
322
+ map "inningHalf", to: :inning_half
323
+ map "isTopInning", to: :is_top_inning
324
+ map "scheduledInnings", to: :scheduled_innings
325
+ map "innings", to: :innings
326
+ map "teams", to: :teams
327
+ end
328
+
329
+ # Retrieves the linescore for a game
330
+ #
331
+ # @api public
332
+ # @example Get linescore for a game
333
+ # MLB::Linescore.find(game: 745726)
334
+ # @param game [ScheduledGame, Integer] the game or game PK
335
+ # @return [Linescore] the linescore
336
+ def self.find(game:)
337
+ game_pk = game.respond_to?(:game_pk) ? game.game_pk : game
338
+ response = CLIENT.get("game/#{game_pk}/linescore")
339
+ from_json(response)
340
+ end
341
+ end
342
+ end
@@ -0,0 +1,89 @@
1
+ require "shale"
2
+ require_relative "inning_score"
3
+
4
+ module MLB
5
+ # Represents one team's linescore totals
6
+ class LinescoreTeam < Shale::Mapper
7
+ # @!attribute [rw] runs
8
+ # Returns total runs
9
+ # @api public
10
+ # @example
11
+ # linescore_team.runs #=> 8
12
+ # @return [Integer] the runs
13
+ attribute :runs, Shale::Type::Integer
14
+
15
+ # @!attribute [rw] hits
16
+ # Returns total hits
17
+ # @api public
18
+ # @example
19
+ # linescore_team.hits #=> 9
20
+ # @return [Integer] the hits
21
+ attribute :hits, Shale::Type::Integer
22
+
23
+ # @!attribute [rw] errors
24
+ # Returns total errors
25
+ # @api public
26
+ # @example
27
+ # linescore_team.errors #=> 0
28
+ # @return [Integer] the errors
29
+ attribute :errors, Shale::Type::Integer
30
+
31
+ # @!attribute [rw] left_on_base
32
+ # Returns total left on base
33
+ # @api public
34
+ # @example
35
+ # linescore_team.left_on_base #=> 5
36
+ # @return [Integer] the left on base
37
+ attribute :left_on_base, Shale::Type::Integer
38
+
39
+ # @!attribute [rw] is_winner
40
+ # Returns whether this team won
41
+ # @api public
42
+ # @example
43
+ # linescore_team.winner? #=> true
44
+ # @return [Boolean] whether this team won
45
+ attribute :is_winner, Shale::Type::Boolean
46
+
47
+ # Returns whether this team won
48
+ #
49
+ # @api public
50
+ # @example
51
+ # linescore_team.winner? #=> true
52
+ # @return [Boolean] whether this team won
53
+ def winner?
54
+ is_winner
55
+ end
56
+
57
+ json do
58
+ map "runs", to: :runs
59
+ map "hits", to: :hits
60
+ map "errors", to: :errors
61
+ map "leftOnBase", to: :left_on_base
62
+ map "isWinner", to: :is_winner
63
+ end
64
+ end
65
+
66
+ # Represents both teams' linescore totals
67
+ class LinescoreTeams < Shale::Mapper
68
+ # @!attribute [rw] home
69
+ # Returns the home team's totals
70
+ # @api public
71
+ # @example
72
+ # linescore_teams.home #=> #<MLB::LinescoreTeam>
73
+ # @return [LinescoreTeam] the home team
74
+ attribute :home, LinescoreTeam
75
+
76
+ # @!attribute [rw] away
77
+ # Returns the away team's totals
78
+ # @api public
79
+ # @example
80
+ # linescore_teams.away #=> #<MLB::LinescoreTeam>
81
+ # @return [LinescoreTeam] the away team
82
+ attribute :away, LinescoreTeam
83
+
84
+ json do
85
+ map "home", to: :home
86
+ map "away", to: :away
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,130 @@
1
+ require "shale"
2
+ require_relative "game_data"
3
+ require_relative "play"
4
+ require_relative "linescore"
5
+ require_relative "boxscore"
6
+
7
+ module MLB
8
+ # Represents the plays section of the live feed
9
+ class LivePlays < Shale::Mapper
10
+ # @!attribute [rw] all_plays
11
+ # Returns all plays in the game
12
+ # @api public
13
+ # @example
14
+ # plays.all_plays #=> [#<MLB::Play>, ...]
15
+ # @return [Array<Play>] all plays
16
+ attribute :all_plays, Play, collection: true
17
+
18
+ # @!attribute [rw] current_play
19
+ # Returns the current play
20
+ # @api public
21
+ # @example
22
+ # plays.current_play #=> #<MLB::Play>
23
+ # @return [Play] the current play
24
+ attribute :current_play, Play
25
+
26
+ # @!attribute [rw] scoring_plays
27
+ # Returns indices of scoring plays
28
+ # @api public
29
+ # @example
30
+ # plays.scoring_plays #=> [5, 12, 23]
31
+ # @return [Array<Integer>] scoring play indices
32
+ attribute :scoring_plays, Shale::Type::Integer, collection: true
33
+
34
+ json do
35
+ map "allPlays", to: :all_plays
36
+ map "currentPlay", to: :current_play
37
+ map "scoringPlays", to: :scoring_plays
38
+ end
39
+ end
40
+
41
+ # Represents the live data section of the feed
42
+ class LiveData < Shale::Mapper
43
+ # @!attribute [rw] plays
44
+ # Returns the plays data
45
+ # @api public
46
+ # @example
47
+ # live_data.plays #=> #<MLB::LivePlays>
48
+ # @return [LivePlays] the plays
49
+ attribute :plays, LivePlays
50
+
51
+ # @!attribute [rw] linescore
52
+ # Returns the linescore
53
+ # @api public
54
+ # @example
55
+ # live_data.linescore #=> #<MLB::Linescore>
56
+ # @return [Linescore] the linescore
57
+ attribute :linescore, Linescore
58
+
59
+ # @!attribute [rw] boxscore
60
+ # Returns the boxscore
61
+ # @api public
62
+ # @example
63
+ # live_data.boxscore #=> #<MLB::Boxscore>
64
+ # @return [Boxscore] the boxscore
65
+ attribute :boxscore, Boxscore
66
+
67
+ json do
68
+ map "plays", to: :plays
69
+ map "linescore", to: :linescore
70
+ map "boxscore", to: :boxscore
71
+ end
72
+ end
73
+
74
+ # Represents the live game feed data
75
+ class LiveFeed < Shale::Mapper
76
+ # @!attribute [rw] game_pk
77
+ # Returns the game primary key
78
+ # @api public
79
+ # @example
80
+ # feed.game_pk #=> 745571
81
+ # @return [Integer] the game PK
82
+ attribute :game_pk, Shale::Type::Integer
83
+
84
+ # @!attribute [rw] link
85
+ # Returns the API link
86
+ # @api public
87
+ # @example
88
+ # feed.link #=> "/api/v1.1/game/745571/feed/live"
89
+ # @return [String] the link
90
+ attribute :link, Shale::Type::String
91
+
92
+ # @!attribute [rw] game_data
93
+ # Returns the game metadata
94
+ # @api public
95
+ # @example
96
+ # feed.game_data #=> #<MLB::GameData>
97
+ # @return [GameData] the game data
98
+ attribute :game_data, GameData
99
+
100
+ # @!attribute [rw] live_data
101
+ # Returns the live game data
102
+ # @api public
103
+ # @example
104
+ # feed.live_data #=> #<MLB::LiveData>
105
+ # @return [LiveData] the live data
106
+ attribute :live_data, LiveData
107
+
108
+ json do
109
+ map "gamePk", to: :game_pk
110
+ map "link", to: :link
111
+ map "gameData", to: :game_data
112
+ map "liveData", to: :live_data
113
+ end
114
+
115
+ # Retrieves the live feed for a game
116
+ #
117
+ # @api public
118
+ # @example Get live feed for a game
119
+ # MLB::LiveFeed.find(game: 745571)
120
+ # @example Get live feed using a ScheduledGame object
121
+ # MLB::LiveFeed.find(game: scheduled_game)
122
+ # @param game [Integer, ScheduledGame] the game ID or game object
123
+ # @return [LiveFeed] the live feed
124
+ def self.find(game:)
125
+ game_pk = game.respond_to?(:game_pk) ? game.game_pk : game
126
+ response = CLIENT.get("game/#{game_pk}/feed/live")
127
+ from_json(response)
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,17 @@
1
+ require "equalizer"
2
+ require "shale"
3
+
4
+ module MLB
5
+ # Represents a logical event code
6
+ class LogicalEvent < Shale::Mapper
7
+ include Equalizer.new(:code)
8
+
9
+ # @!attribute [rw] code
10
+ # Returns the logical event code
11
+ # @api public
12
+ # @example
13
+ # logical_event.code #=> "countChange"
14
+ # @return [String] the logical event code
15
+ attribute :code, Shale::Type::String
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "collection"
2
+ require_relative "logical_event"
3
+
4
+ module MLB
5
+ # Provides methods for fetching logical events from the API
6
+ #
7
+ # @example Fetch all logical events
8
+ # MLB::LogicalEvents.all #=> [#<MLB::LogicalEvent>, ...]
9
+ class LogicalEvents < Collection
10
+ collection endpoint: "logicalEvents", item_type: LogicalEvent, collection_name: :logical_events
11
+ end
12
+ end
data/lib/mlb/metric.rb ADDED
@@ -0,0 +1,48 @@
1
+ require "equalizer"
2
+ require "shale"
3
+
4
+ module MLB
5
+ # Represents a statcast metric
6
+ class Metric < Shale::Mapper
7
+ include Equalizer.new(:metric_id)
8
+
9
+ # @!attribute [rw] name
10
+ # Returns the metric name
11
+ # @api public
12
+ # @example
13
+ # metric.name #=> "launchSpeed"
14
+ # @return [String] the metric name
15
+ attribute :name, Shale::Type::String
16
+
17
+ # @!attribute [rw] metric_id
18
+ # Returns the unique metric identifier
19
+ # @api public
20
+ # @example
21
+ # metric.metric_id #=> 1
22
+ # @return [Integer] the unique metric identifier
23
+ attribute :metric_id, Shale::Type::Integer
24
+
25
+ # @!attribute [rw] group
26
+ # Returns the metric group
27
+ # @api public
28
+ # @example
29
+ # metric.group #=> "hitting"
30
+ # @return [String] the metric group
31
+ attribute :group, Shale::Type::String
32
+
33
+ # @!attribute [rw] unit
34
+ # Returns the measurement unit
35
+ # @api public
36
+ # @example
37
+ # metric.unit #=> "MPH"
38
+ # @return [String] the measurement unit
39
+ attribute :unit, Shale::Type::String
40
+
41
+ json do
42
+ map "name", to: :name
43
+ map "metricId", to: :metric_id
44
+ map "group", to: :group
45
+ map "unit", to: :unit
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "collection"
2
+ require_relative "metric"
3
+
4
+ module MLB
5
+ # Provides methods for fetching metrics from the API
6
+ #
7
+ # @example Fetch all metrics
8
+ # MLB::Metrics.all #=> [#<MLB::Metric>, ...]
9
+ class Metrics < Collection
10
+ collection endpoint: "metrics", item_type: Metric, collection_name: :metrics
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ require "shale"
2
+ require "uri"
3
+ require_relative "player"
4
+
5
+ module MLB
6
+ # Provides methods for fetching people changes from the API
7
+ class PeopleChanges < Shale::Mapper
8
+ # @!attribute [rw] people
9
+ # Returns the changed people
10
+ # @api public
11
+ # @example
12
+ # people_changes.people #=> [#<MLB::Player>, ...]
13
+ # @return [Array<Player>] the changed people
14
+ attribute :people, Player, collection: true
15
+
16
+ json do
17
+ map "people", to: :people
18
+ end
19
+
20
+ # Retrieves people changes since a date
21
+ #
22
+ # @api public
23
+ # @example Get people changes since a date
24
+ # MLB::PeopleChanges.since(date: Date.new(2024, 6, 1))
25
+ # @param date [Date] the date to check changes from
26
+ # @return [Array<Player>] the changed people
27
+ def self.since(date:)
28
+ params = {updatedSince: date.to_s}
29
+ query_string = URI.encode_www_form(params)
30
+ response = CLIENT.get("people/changes?#{query_string}")
31
+ from_json(response).people
32
+ end
33
+ end
34
+ end