mlb 0.9.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -1
- data/LICENSE.txt +1 -1
- data/README.md +329 -32
- data/lib/mlb/affiliates.rb +28 -0
- data/lib/mlb/alumni.rb +30 -0
- data/lib/mlb/attendance.rb +28 -0
- data/lib/mlb/attendance_record.rb +157 -0
- data/lib/mlb/award.rb +126 -0
- data/lib/mlb/awards.rb +32 -0
- data/lib/mlb/baseball_stat.rb +65 -0
- data/lib/mlb/baseball_stats.rb +12 -0
- data/lib/mlb/boxscore.rb +81 -0
- data/lib/mlb/boxscore_team_stats.rb +210 -0
- data/lib/mlb/client.rb +71 -1
- data/lib/mlb/coaches.rb +28 -0
- data/lib/mlb/code_description_type.rb +45 -0
- data/lib/mlb/collection.rb +48 -0
- data/lib/mlb/comparable_by_attribute.rb +56 -0
- data/lib/mlb/conference.rb +39 -0
- data/lib/mlb/conferences.rb +33 -0
- data/lib/mlb/connection.rb +130 -7
- data/lib/mlb/context_metrics.rb +90 -0
- data/lib/mlb/division.rb +26 -6
- data/lib/mlb/divisions.rb +24 -18
- data/lib/mlb/draft.rb +83 -0
- data/lib/mlb/draft_pick.rb +155 -0
- data/lib/mlb/error_handler.rb +21 -1
- data/lib/mlb/errors/bad_gateway.rb +6 -1
- data/lib/mlb/errors/bad_request.rb +1 -0
- data/lib/mlb/errors/client_error.rb +1 -0
- data/lib/mlb/errors/connection_exception.rb +1 -0
- data/lib/mlb/errors/error.rb +1 -0
- data/lib/mlb/errors/forbidden.rb +1 -0
- data/lib/mlb/errors/gateway_timeout.rb +6 -1
- data/lib/mlb/errors/gone.rb +1 -0
- data/lib/mlb/errors/http_error.rb +22 -2
- data/lib/mlb/errors/internal_server_error.rb +1 -0
- data/lib/mlb/errors/network_error.rb +6 -1
- data/lib/mlb/errors/not_acceptable.rb +1 -0
- data/lib/mlb/errors/not_found.rb +1 -0
- data/lib/mlb/errors/payload_too_large.rb +1 -0
- data/lib/mlb/errors/retryable.rb +15 -0
- data/lib/mlb/errors/server_error.rb +1 -0
- data/lib/mlb/errors/service_unavailable.rb +6 -1
- data/lib/mlb/errors/too_many_redirects.rb +1 -0
- data/lib/mlb/errors/too_many_requests.rb +6 -1
- data/lib/mlb/errors/unauthorized.rb +1 -0
- data/lib/mlb/errors/unprocessable_entity.rb +1 -0
- data/lib/mlb/event_type.rb +61 -0
- data/lib/mlb/event_types.rb +12 -0
- data/lib/mlb/free_agent.rb +78 -0
- data/lib/mlb/free_agents.rb +34 -0
- data/lib/mlb/game_changes.rb +87 -0
- data/lib/mlb/game_content.rb +251 -0
- data/lib/mlb/game_data.rb +155 -0
- data/lib/mlb/game_pace.rb +173 -0
- data/lib/mlb/game_status.rb +94 -0
- data/lib/mlb/game_statuses.rb +12 -0
- data/lib/mlb/game_type.rb +98 -0
- data/lib/mlb/game_types.rb +12 -0
- data/lib/mlb/handedness.rb +30 -9
- data/lib/mlb/high_low.rb +121 -0
- data/lib/mlb/hit_trajectories.rb +12 -0
- data/lib/mlb/hit_trajectory.rb +6 -0
- data/lib/mlb/home_run_derby.rb +285 -0
- data/lib/mlb/id_description_type.rb +44 -0
- data/lib/mlb/inning_score.rb +87 -0
- data/lib/mlb/job.rb +58 -0
- data/lib/mlb/job_type.rb +39 -0
- data/lib/mlb/job_types.rb +12 -0
- data/lib/mlb/jobs.rb +87 -0
- data/lib/mlb/language.rb +48 -0
- data/lib/mlb/languages.rb +12 -0
- data/lib/mlb/leader.rb +79 -0
- data/lib/mlb/leaders.rb +68 -0
- data/lib/mlb/league.rb +97 -14
- data/lib/mlb/league_leader_type.rb +21 -0
- data/lib/mlb/league_leader_types.rb +12 -0
- data/lib/mlb/leagues.rb +24 -18
- data/lib/mlb/linescore.rb +342 -0
- data/lib/mlb/linescore_teams.rb +89 -0
- data/lib/mlb/live_feed.rb +130 -0
- data/lib/mlb/logical_event.rb +17 -0
- data/lib/mlb/logical_events.rb +12 -0
- data/lib/mlb/metric.rb +48 -0
- data/lib/mlb/metrics.rb +12 -0
- data/lib/mlb/people_changes.rb +34 -0
- data/lib/mlb/personnel.rb +28 -0
- data/lib/mlb/pitch_code.rb +90 -0
- data/lib/mlb/pitch_codes.rb +12 -0
- data/lib/mlb/pitch_type.rb +6 -0
- data/lib/mlb/pitch_types.rb +12 -0
- data/lib/mlb/platform.rb +30 -0
- data/lib/mlb/platforms.rb +12 -0
- data/lib/mlb/play.rb +300 -0
- data/lib/mlb/play_by_play.rb +52 -0
- data/lib/mlb/player.rb +186 -0
- data/lib/mlb/player_game_stats.rb +350 -0
- data/lib/mlb/player_stat.rb +70 -0
- data/lib/mlb/players.rb +42 -11
- data/lib/mlb/position.rb +68 -0
- data/lib/mlb/positions.rb +12 -0
- data/lib/mlb/postseason_schedule.rb +41 -0
- data/lib/mlb/postseason_series.rb +54 -0
- data/lib/mlb/redirect_handler.rb +80 -21
- data/lib/mlb/request_builder.rb +33 -2
- data/lib/mlb/review_reason.rb +6 -0
- data/lib/mlb/review_reasons.rb +12 -0
- data/lib/mlb/roster.rb +16 -12
- data/lib/mlb/roster_entry.rb +38 -0
- data/lib/mlb/roster_type.rb +39 -0
- data/lib/mlb/roster_types.rb +12 -0
- data/lib/mlb/schedule.rb +33 -0
- data/lib/mlb/schedule_date.rb +37 -0
- data/lib/mlb/schedule_event_type.rb +25 -0
- data/lib/mlb/schedule_event_types.rb +12 -0
- data/lib/mlb/scheduled_game.rb +321 -0
- data/lib/mlb/season.rb +74 -0
- data/lib/mlb/season_date_info.rb +4 -0
- data/lib/mlb/seasons.rb +36 -0
- data/lib/mlb/single_team_stats.rb +33 -0
- data/lib/mlb/situation_code.rb +116 -0
- data/lib/mlb/situation_codes.rb +12 -0
- data/lib/mlb/skies.rb +12 -0
- data/lib/mlb/sky.rb +6 -0
- data/lib/mlb/sport.rb +18 -5
- data/lib/mlb/sport_players.rb +30 -0
- data/lib/mlb/sports.rb +17 -7
- data/lib/mlb/standings.rb +47 -0
- data/lib/mlb/standings_record.rb +108 -0
- data/lib/mlb/standings_type.rb +25 -0
- data/lib/mlb/standings_types.rb +12 -0
- data/lib/mlb/stat_group.rb +21 -0
- data/lib/mlb/stat_groups.rb +12 -0
- data/lib/mlb/stat_type.rb +21 -0
- data/lib/mlb/stat_types.rb +12 -0
- data/lib/mlb/stat_values.rb +158 -0
- data/lib/mlb/stats.rb +41 -0
- data/lib/mlb/status.rb +17 -0
- data/lib/mlb/streaks.rb +184 -0
- data/lib/mlb/team.rb +66 -7
- data/lib/mlb/team_history.rb +28 -0
- data/lib/mlb/team_leader.rb +59 -0
- data/lib/mlb/team_leaders.rb +45 -0
- data/lib/mlb/team_record.rb +285 -0
- data/lib/mlb/team_stat.rb +50 -0
- data/lib/mlb/team_stats.rb +52 -0
- data/lib/mlb/teams.rb +28 -18
- data/lib/mlb/tied_games.rb +32 -0
- data/lib/mlb/transaction.rb +128 -0
- data/lib/mlb/transactions.rb +11 -6
- data/lib/mlb/uniforms.rb +97 -0
- data/lib/mlb/utils.rb +45 -0
- data/lib/mlb/venue.rb +10 -0
- data/lib/mlb/venues.rb +28 -18
- data/lib/mlb/version.rb +2 -1
- data/lib/mlb/win_probability.rb +64 -0
- data/lib/mlb/wind_direction.rb +6 -0
- data/lib/mlb/wind_directions.rb +12 -0
- data/lib/mlb.rb +64 -0
- data/sig/equalizer.rbs +3 -0
- data/sig/mlb.rbs +1972 -103
- data/sig/shale.rbs +29 -0
- metadata +137 -14
data/lib/mlb/player.rb
CHANGED
|
@@ -1,35 +1,220 @@
|
|
|
1
|
+
require "equalizer"
|
|
1
2
|
require "shale"
|
|
2
3
|
require_relative "position"
|
|
3
4
|
require_relative "handedness"
|
|
4
5
|
require_relative "team"
|
|
5
6
|
|
|
6
7
|
module MLB
|
|
8
|
+
# Represents an MLB player with biographical and career information
|
|
7
9
|
class Player < Shale::Mapper
|
|
10
|
+
include Equalizer.new(:id)
|
|
11
|
+
|
|
12
|
+
# @!attribute [rw] id
|
|
13
|
+
# Returns the unique identifier for the player
|
|
14
|
+
# @api public
|
|
15
|
+
# @example
|
|
16
|
+
# player.id #=> 660271
|
|
17
|
+
# @return [Integer] the unique identifier for the player
|
|
8
18
|
attribute :id, Shale::Type::Integer
|
|
19
|
+
|
|
20
|
+
# @!attribute [rw] full_name
|
|
21
|
+
# Returns the player's full name
|
|
22
|
+
# @api public
|
|
23
|
+
# @example
|
|
24
|
+
# player.full_name #=> "Shohei Ohtani"
|
|
25
|
+
# @return [String] the player's full name
|
|
9
26
|
attribute :full_name, Shale::Type::String
|
|
27
|
+
|
|
28
|
+
# @!attribute [rw] link
|
|
29
|
+
# Returns the API link for the player
|
|
30
|
+
# @api public
|
|
31
|
+
# @example
|
|
32
|
+
# player.link #=> "/api/v1/people/660271"
|
|
33
|
+
# @return [String] the API link for the player
|
|
10
34
|
attribute :link, Shale::Type::String
|
|
35
|
+
|
|
36
|
+
# @!attribute [rw] first_name
|
|
37
|
+
# Returns the player's first name
|
|
38
|
+
# @api public
|
|
39
|
+
# @example
|
|
40
|
+
# player.first_name #=> "Shohei"
|
|
41
|
+
# @return [String] the player's first name
|
|
11
42
|
attribute :first_name, Shale::Type::String
|
|
43
|
+
|
|
44
|
+
# @!attribute [rw] last_name
|
|
45
|
+
# Returns the player's last name
|
|
46
|
+
# @api public
|
|
47
|
+
# @example
|
|
48
|
+
# player.last_name #=> "Ohtani"
|
|
49
|
+
# @return [String] the player's last name
|
|
12
50
|
attribute :last_name, Shale::Type::String
|
|
51
|
+
|
|
52
|
+
# @!attribute [rw] primary_number
|
|
53
|
+
# Returns the player's primary jersey number
|
|
54
|
+
# @api public
|
|
55
|
+
# @example
|
|
56
|
+
# player.primary_number #=> 17
|
|
57
|
+
# @return [Integer] the player's primary jersey number
|
|
13
58
|
attribute :primary_number, Shale::Type::Integer
|
|
59
|
+
|
|
60
|
+
# @!attribute [rw] birth_date
|
|
61
|
+
# Returns the player's date of birth
|
|
62
|
+
# @api public
|
|
63
|
+
# @example
|
|
64
|
+
# player.birth_date #=> #<Date: 1994-07-05>
|
|
65
|
+
# @return [Date] the player's date of birth
|
|
14
66
|
attribute :birth_date, Shale::Type::Date
|
|
67
|
+
|
|
68
|
+
# @!attribute [rw] current_age
|
|
69
|
+
# Returns the player's current age
|
|
70
|
+
# @api public
|
|
71
|
+
# @example
|
|
72
|
+
# player.current_age #=> 30
|
|
73
|
+
# @return [Integer] the player's current age
|
|
15
74
|
attribute :current_age, Shale::Type::Integer
|
|
75
|
+
|
|
76
|
+
# @!attribute [rw] birth_city
|
|
77
|
+
# Returns the player's birth city
|
|
78
|
+
# @api public
|
|
79
|
+
# @example
|
|
80
|
+
# player.birth_city #=> "Oshu"
|
|
81
|
+
# @return [String] the player's birth city
|
|
16
82
|
attribute :birth_city, Shale::Type::String
|
|
83
|
+
|
|
84
|
+
# @!attribute [rw] birth_state_province
|
|
85
|
+
# Returns the player's birth state or province
|
|
86
|
+
# @api public
|
|
87
|
+
# @example
|
|
88
|
+
# player.birth_state_province #=> "Iwate"
|
|
89
|
+
# @return [String] the player's birth state or province
|
|
17
90
|
attribute :birth_state_province, Shale::Type::String
|
|
91
|
+
|
|
92
|
+
# @!attribute [rw] birth_country
|
|
93
|
+
# Returns the player's birth country
|
|
94
|
+
# @api public
|
|
95
|
+
# @example
|
|
96
|
+
# player.birth_country #=> "Japan"
|
|
97
|
+
# @return [String] the player's birth country
|
|
18
98
|
attribute :birth_country, Shale::Type::String
|
|
99
|
+
|
|
100
|
+
# @!attribute [rw] height
|
|
101
|
+
# Returns the player's height
|
|
102
|
+
# @api public
|
|
103
|
+
# @example
|
|
104
|
+
# player.height #=> "6' 4\""
|
|
105
|
+
# @return [String] the player's height
|
|
19
106
|
attribute :height, Shale::Type::String
|
|
107
|
+
|
|
108
|
+
# @!attribute [rw] weight
|
|
109
|
+
# Returns the player's weight in pounds
|
|
110
|
+
# @api public
|
|
111
|
+
# @example
|
|
112
|
+
# player.weight #=> 210
|
|
113
|
+
# @return [Integer] the player's weight in pounds
|
|
20
114
|
attribute :weight, Shale::Type::Integer
|
|
115
|
+
|
|
116
|
+
# @!attribute [rw] active
|
|
117
|
+
# Returns whether the player is currently active
|
|
118
|
+
# @api public
|
|
119
|
+
# @example
|
|
120
|
+
# player.active #=> true
|
|
121
|
+
# @return [Boolean] whether the player is currently active
|
|
21
122
|
attribute :active, Shale::Type::Boolean
|
|
123
|
+
|
|
124
|
+
# @!attribute [rw] current_team
|
|
125
|
+
# Returns the player's current team
|
|
126
|
+
# @api public
|
|
127
|
+
# @example
|
|
128
|
+
# player.current_team #=> #<MLB::Team>
|
|
129
|
+
# @return [Team] the player's current team
|
|
22
130
|
attribute :current_team, Team
|
|
131
|
+
|
|
132
|
+
# @!attribute [rw] primary_position
|
|
133
|
+
# Returns the player's primary position
|
|
134
|
+
# @api public
|
|
135
|
+
# @example
|
|
136
|
+
# player.primary_position #=> #<MLB::Position>
|
|
137
|
+
# @return [Position] the player's primary position
|
|
23
138
|
attribute :primary_position, Position
|
|
139
|
+
|
|
140
|
+
# @!attribute [rw] use_name
|
|
141
|
+
# Returns the player's preferred name
|
|
142
|
+
# @api public
|
|
143
|
+
# @example
|
|
144
|
+
# player.use_name #=> "Shohei"
|
|
145
|
+
# @return [String] the player's preferred name
|
|
24
146
|
attribute :use_name, Shale::Type::String
|
|
147
|
+
|
|
148
|
+
# @!attribute [rw] middle_name
|
|
149
|
+
# Returns the player's middle name
|
|
150
|
+
# @api public
|
|
151
|
+
# @example
|
|
152
|
+
# player.middle_name #=> "James"
|
|
153
|
+
# @return [String] the player's middle name
|
|
25
154
|
attribute :middle_name, Shale::Type::String
|
|
155
|
+
|
|
156
|
+
# @!attribute [rw] boxscore_name
|
|
157
|
+
# Returns the player's name as displayed in boxscores
|
|
158
|
+
# @api public
|
|
159
|
+
# @example
|
|
160
|
+
# player.boxscore_name #=> "Ohtani"
|
|
161
|
+
# @return [String] the player's name as displayed in boxscores
|
|
26
162
|
attribute :boxscore_name, Shale::Type::String
|
|
163
|
+
|
|
164
|
+
# @!attribute [rw] gender
|
|
165
|
+
# Returns the player's gender
|
|
166
|
+
# @api public
|
|
167
|
+
# @example
|
|
168
|
+
# player.gender #=> "M"
|
|
169
|
+
# @return [String] the player's gender
|
|
27
170
|
attribute :gender, Shale::Type::String
|
|
171
|
+
|
|
172
|
+
# @!attribute [rw] is_player
|
|
173
|
+
# Returns whether the person is a player
|
|
174
|
+
# @api public
|
|
175
|
+
# @example
|
|
176
|
+
# player.is_player #=> true
|
|
177
|
+
# @return [Boolean] whether the person is a player
|
|
28
178
|
attribute :is_player, Shale::Type::Boolean
|
|
179
|
+
|
|
180
|
+
# @!attribute [rw] is_verified
|
|
181
|
+
# Returns whether the player's information is verified
|
|
182
|
+
# @api public
|
|
183
|
+
# @example
|
|
184
|
+
# player.is_verified #=> true
|
|
185
|
+
# @return [Boolean] whether the player's information is verified
|
|
29
186
|
attribute :is_verified, Shale::Type::Boolean
|
|
187
|
+
|
|
188
|
+
# @!attribute [rw] draft_year
|
|
189
|
+
# Returns the year the player was drafted
|
|
190
|
+
# @api public
|
|
191
|
+
# @example
|
|
192
|
+
# player.draft_year #=> 2018
|
|
193
|
+
# @return [Integer] the year the player was drafted
|
|
30
194
|
attribute :draft_year, Shale::Type::Integer
|
|
195
|
+
|
|
196
|
+
# @!attribute [rw] mlb_debut_date
|
|
197
|
+
# Returns the date of the player's MLB debut
|
|
198
|
+
# @api public
|
|
199
|
+
# @example
|
|
200
|
+
# player.mlb_debut_date #=> #<Date: 2018-03-29>
|
|
201
|
+
# @return [Date] the date of the player's MLB debut
|
|
31
202
|
attribute :mlb_debut_date, Shale::Type::Date
|
|
203
|
+
|
|
204
|
+
# @!attribute [rw] bat_side
|
|
205
|
+
# Returns the player's batting side
|
|
206
|
+
# @api public
|
|
207
|
+
# @example
|
|
208
|
+
# player.bat_side #=> #<MLB::Handedness>
|
|
209
|
+
# @return [Handedness] the player's batting side
|
|
32
210
|
attribute :bat_side, Handedness
|
|
211
|
+
|
|
212
|
+
# @!attribute [rw] pitch_hand
|
|
213
|
+
# Returns the player's pitching hand
|
|
214
|
+
# @api public
|
|
215
|
+
# @example
|
|
216
|
+
# player.pitch_hand #=> #<MLB::Handedness>
|
|
217
|
+
# @return [Handedness] the player's pitching hand
|
|
33
218
|
attribute :pitch_hand, Handedness
|
|
34
219
|
|
|
35
220
|
alias_method :verified?, :is_verified
|
|
@@ -39,6 +224,7 @@ module MLB
|
|
|
39
224
|
json do
|
|
40
225
|
map "id", to: :id
|
|
41
226
|
map "fullName", to: :full_name
|
|
227
|
+
map "nameFirstLast", to: :full_name
|
|
42
228
|
map "link", to: :link
|
|
43
229
|
map "firstName", to: :first_name
|
|
44
230
|
map "lastName", to: :last_name
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
require "shale"
|
|
2
|
+
require_relative "player"
|
|
3
|
+
require_relative "team"
|
|
4
|
+
|
|
5
|
+
module MLB
|
|
6
|
+
# Represents a player's batting stats for a game
|
|
7
|
+
class PlayerGameBattingStats < Shale::Mapper
|
|
8
|
+
# @!attribute [rw] games_played
|
|
9
|
+
# Returns games played
|
|
10
|
+
# @api public
|
|
11
|
+
# @example
|
|
12
|
+
# stats.games_played #=> 1
|
|
13
|
+
# @return [Integer] games played
|
|
14
|
+
attribute :games_played, Shale::Type::Integer
|
|
15
|
+
|
|
16
|
+
# @!attribute [rw] at_bats
|
|
17
|
+
# Returns at bats
|
|
18
|
+
# @api public
|
|
19
|
+
# @example
|
|
20
|
+
# stats.at_bats #=> 4
|
|
21
|
+
# @return [Integer] at bats
|
|
22
|
+
attribute :at_bats, Shale::Type::Integer
|
|
23
|
+
|
|
24
|
+
# @!attribute [rw] runs
|
|
25
|
+
# Returns runs scored
|
|
26
|
+
# @api public
|
|
27
|
+
# @example
|
|
28
|
+
# stats.runs #=> 1
|
|
29
|
+
# @return [Integer] runs
|
|
30
|
+
attribute :runs, Shale::Type::Integer
|
|
31
|
+
|
|
32
|
+
# @!attribute [rw] hits
|
|
33
|
+
# Returns hits
|
|
34
|
+
# @api public
|
|
35
|
+
# @example
|
|
36
|
+
# stats.hits #=> 2
|
|
37
|
+
# @return [Integer] hits
|
|
38
|
+
attribute :hits, Shale::Type::Integer
|
|
39
|
+
|
|
40
|
+
# @!attribute [rw] doubles
|
|
41
|
+
# Returns doubles
|
|
42
|
+
# @api public
|
|
43
|
+
# @example
|
|
44
|
+
# stats.doubles #=> 1
|
|
45
|
+
# @return [Integer] doubles
|
|
46
|
+
attribute :doubles, Shale::Type::Integer
|
|
47
|
+
|
|
48
|
+
# @!attribute [rw] triples
|
|
49
|
+
# Returns triples
|
|
50
|
+
# @api public
|
|
51
|
+
# @example
|
|
52
|
+
# stats.triples #=> 0
|
|
53
|
+
# @return [Integer] triples
|
|
54
|
+
attribute :triples, Shale::Type::Integer
|
|
55
|
+
|
|
56
|
+
# @!attribute [rw] home_runs
|
|
57
|
+
# Returns home runs
|
|
58
|
+
# @api public
|
|
59
|
+
# @example
|
|
60
|
+
# stats.home_runs #=> 1
|
|
61
|
+
# @return [Integer] home runs
|
|
62
|
+
attribute :home_runs, Shale::Type::Integer
|
|
63
|
+
|
|
64
|
+
# @!attribute [rw] rbi
|
|
65
|
+
# Returns RBIs
|
|
66
|
+
# @api public
|
|
67
|
+
# @example
|
|
68
|
+
# stats.rbi #=> 3
|
|
69
|
+
# @return [Integer] RBIs
|
|
70
|
+
attribute :rbi, Shale::Type::Integer
|
|
71
|
+
|
|
72
|
+
# @!attribute [rw] stolen_bases
|
|
73
|
+
# Returns stolen bases
|
|
74
|
+
# @api public
|
|
75
|
+
# @example
|
|
76
|
+
# stats.stolen_bases #=> 0
|
|
77
|
+
# @return [Integer] stolen bases
|
|
78
|
+
attribute :stolen_bases, Shale::Type::Integer
|
|
79
|
+
|
|
80
|
+
# @!attribute [rw] base_on_balls
|
|
81
|
+
# Returns walks
|
|
82
|
+
# @api public
|
|
83
|
+
# @example
|
|
84
|
+
# stats.base_on_balls #=> 1
|
|
85
|
+
# @return [Integer] walks
|
|
86
|
+
attribute :base_on_balls, Shale::Type::Integer
|
|
87
|
+
|
|
88
|
+
# @!attribute [rw] strike_outs
|
|
89
|
+
# Returns strikeouts
|
|
90
|
+
# @api public
|
|
91
|
+
# @example
|
|
92
|
+
# stats.strike_outs #=> 1
|
|
93
|
+
# @return [Integer] strikeouts
|
|
94
|
+
attribute :strike_outs, Shale::Type::Integer
|
|
95
|
+
|
|
96
|
+
json do
|
|
97
|
+
map "gamesPlayed", to: :games_played
|
|
98
|
+
map "atBats", to: :at_bats
|
|
99
|
+
map "runs", to: :runs
|
|
100
|
+
map "hits", to: :hits
|
|
101
|
+
map "doubles", to: :doubles
|
|
102
|
+
map "triples", to: :triples
|
|
103
|
+
map "homeRuns", to: :home_runs
|
|
104
|
+
map "rbi", to: :rbi
|
|
105
|
+
map "stolenBases", to: :stolen_bases
|
|
106
|
+
map "baseOnBalls", to: :base_on_balls
|
|
107
|
+
map "strikeOuts", to: :strike_outs
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Represents a player's pitching stats for a game
|
|
112
|
+
class PlayerGamePitchingStats < Shale::Mapper
|
|
113
|
+
# @!attribute [rw] games_played
|
|
114
|
+
# Returns games played
|
|
115
|
+
# @api public
|
|
116
|
+
# @example
|
|
117
|
+
# stats.games_played #=> 1
|
|
118
|
+
# @return [Integer] games played
|
|
119
|
+
attribute :games_played, Shale::Type::Integer
|
|
120
|
+
|
|
121
|
+
# @!attribute [rw] games_started
|
|
122
|
+
# Returns games started
|
|
123
|
+
# @api public
|
|
124
|
+
# @example
|
|
125
|
+
# stats.games_started #=> 1
|
|
126
|
+
# @return [Integer] games started
|
|
127
|
+
attribute :games_started, Shale::Type::Integer
|
|
128
|
+
|
|
129
|
+
# @!attribute [rw] wins
|
|
130
|
+
# Returns wins
|
|
131
|
+
# @api public
|
|
132
|
+
# @example
|
|
133
|
+
# stats.wins #=> 1
|
|
134
|
+
# @return [Integer] wins
|
|
135
|
+
attribute :wins, Shale::Type::Integer
|
|
136
|
+
|
|
137
|
+
# @!attribute [rw] losses
|
|
138
|
+
# Returns losses
|
|
139
|
+
# @api public
|
|
140
|
+
# @example
|
|
141
|
+
# stats.losses #=> 0
|
|
142
|
+
# @return [Integer] losses
|
|
143
|
+
attribute :losses, Shale::Type::Integer
|
|
144
|
+
|
|
145
|
+
# @!attribute [rw] saves
|
|
146
|
+
# Returns saves
|
|
147
|
+
# @api public
|
|
148
|
+
# @example
|
|
149
|
+
# stats.saves #=> 0
|
|
150
|
+
# @return [Integer] saves
|
|
151
|
+
attribute :saves, Shale::Type::Integer
|
|
152
|
+
|
|
153
|
+
# @!attribute [rw] innings_pitched
|
|
154
|
+
# Returns innings pitched
|
|
155
|
+
# @api public
|
|
156
|
+
# @example
|
|
157
|
+
# stats.innings_pitched #=> "7.0"
|
|
158
|
+
# @return [String] innings pitched
|
|
159
|
+
attribute :innings_pitched, Shale::Type::String
|
|
160
|
+
|
|
161
|
+
# @!attribute [rw] hits
|
|
162
|
+
# Returns hits allowed
|
|
163
|
+
# @api public
|
|
164
|
+
# @example
|
|
165
|
+
# stats.hits #=> 5
|
|
166
|
+
# @return [Integer] hits allowed
|
|
167
|
+
attribute :hits, Shale::Type::Integer
|
|
168
|
+
|
|
169
|
+
# @!attribute [rw] runs
|
|
170
|
+
# Returns runs allowed
|
|
171
|
+
# @api public
|
|
172
|
+
# @example
|
|
173
|
+
# stats.runs #=> 2
|
|
174
|
+
# @return [Integer] runs allowed
|
|
175
|
+
attribute :runs, Shale::Type::Integer
|
|
176
|
+
|
|
177
|
+
# @!attribute [rw] earned_runs
|
|
178
|
+
# Returns earned runs
|
|
179
|
+
# @api public
|
|
180
|
+
# @example
|
|
181
|
+
# stats.earned_runs #=> 2
|
|
182
|
+
# @return [Integer] earned runs
|
|
183
|
+
attribute :earned_runs, Shale::Type::Integer
|
|
184
|
+
|
|
185
|
+
# @!attribute [rw] home_runs
|
|
186
|
+
# Returns home runs allowed
|
|
187
|
+
# @api public
|
|
188
|
+
# @example
|
|
189
|
+
# stats.home_runs #=> 1
|
|
190
|
+
# @return [Integer] home runs allowed
|
|
191
|
+
attribute :home_runs, Shale::Type::Integer
|
|
192
|
+
|
|
193
|
+
# @!attribute [rw] base_on_balls
|
|
194
|
+
# Returns walks
|
|
195
|
+
# @api public
|
|
196
|
+
# @example
|
|
197
|
+
# stats.base_on_balls #=> 2
|
|
198
|
+
# @return [Integer] walks
|
|
199
|
+
attribute :base_on_balls, Shale::Type::Integer
|
|
200
|
+
|
|
201
|
+
# @!attribute [rw] strike_outs
|
|
202
|
+
# Returns strikeouts
|
|
203
|
+
# @api public
|
|
204
|
+
# @example
|
|
205
|
+
# stats.strike_outs #=> 8
|
|
206
|
+
# @return [Integer] strikeouts
|
|
207
|
+
attribute :strike_outs, Shale::Type::Integer
|
|
208
|
+
|
|
209
|
+
# @!attribute [rw] number_of_pitches
|
|
210
|
+
# Returns pitch count
|
|
211
|
+
# @api public
|
|
212
|
+
# @example
|
|
213
|
+
# stats.number_of_pitches #=> 95
|
|
214
|
+
# @return [Integer] pitch count
|
|
215
|
+
attribute :number_of_pitches, Shale::Type::Integer
|
|
216
|
+
|
|
217
|
+
json do
|
|
218
|
+
map "gamesPlayed", to: :games_played
|
|
219
|
+
map "gamesStarted", to: :games_started
|
|
220
|
+
map "wins", to: :wins
|
|
221
|
+
map "losses", to: :losses
|
|
222
|
+
map "saves", to: :saves
|
|
223
|
+
map "inningsPitched", to: :innings_pitched
|
|
224
|
+
map "hits", to: :hits
|
|
225
|
+
map "runs", to: :runs
|
|
226
|
+
map "earnedRuns", to: :earned_runs
|
|
227
|
+
map "homeRuns", to: :home_runs
|
|
228
|
+
map "baseOnBalls", to: :base_on_balls
|
|
229
|
+
map "strikeOuts", to: :strike_outs
|
|
230
|
+
map "numberOfPitches", to: :number_of_pitches
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
# Represents a player's stat split for a game
|
|
235
|
+
class PlayerGameStatSplit < Shale::Mapper
|
|
236
|
+
# @!attribute [rw] stat
|
|
237
|
+
# Returns the batting stats
|
|
238
|
+
# @api public
|
|
239
|
+
# @example
|
|
240
|
+
# split.stat #=> #<MLB::PlayerGameBattingStats>
|
|
241
|
+
# @return [PlayerGameBattingStats, PlayerGamePitchingStats] the stats
|
|
242
|
+
attribute :stat, Shale::Type::Value
|
|
243
|
+
|
|
244
|
+
# @!attribute [rw] team
|
|
245
|
+
# Returns the team
|
|
246
|
+
# @api public
|
|
247
|
+
# @example
|
|
248
|
+
# split.team #=> #<MLB::Team>
|
|
249
|
+
# @return [Team] the team
|
|
250
|
+
attribute :team, Team
|
|
251
|
+
|
|
252
|
+
# @!attribute [rw] player
|
|
253
|
+
# Returns the player
|
|
254
|
+
# @api public
|
|
255
|
+
# @example
|
|
256
|
+
# split.player #=> #<MLB::Player>
|
|
257
|
+
# @return [Player] the player
|
|
258
|
+
attribute :player, Player
|
|
259
|
+
|
|
260
|
+
json do
|
|
261
|
+
map "stat", to: :stat
|
|
262
|
+
map "team", to: :team
|
|
263
|
+
map "player", to: :player
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# Represents a stat group for a player's game
|
|
268
|
+
class PlayerGameStatGroup < Shale::Mapper
|
|
269
|
+
# @!attribute [rw] group
|
|
270
|
+
# Returns the stat group name
|
|
271
|
+
# @api public
|
|
272
|
+
# @example
|
|
273
|
+
# group.group #=> "hitting"
|
|
274
|
+
# @return [String] the group name
|
|
275
|
+
attribute :group, Shale::Type::String
|
|
276
|
+
|
|
277
|
+
# @!attribute [rw] splits
|
|
278
|
+
# Returns the stat splits
|
|
279
|
+
# @api public
|
|
280
|
+
# @example
|
|
281
|
+
# group.splits #=> [#<MLB::PlayerGameStatSplit>, ...]
|
|
282
|
+
# @return [Array<PlayerGameStatSplit>] the splits
|
|
283
|
+
attribute :splits, PlayerGameStatSplit, collection: true
|
|
284
|
+
|
|
285
|
+
json do
|
|
286
|
+
map "group", to: :group
|
|
287
|
+
map "splits", to: :splits
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
# Provides methods for fetching player game stats from the API
|
|
292
|
+
class PlayerGameStats < Shale::Mapper
|
|
293
|
+
# @!attribute [rw] stats
|
|
294
|
+
# Returns the stat groups
|
|
295
|
+
# @api public
|
|
296
|
+
# @example
|
|
297
|
+
# stats.stats #=> [#<MLB::PlayerGameStatGroup>, ...]
|
|
298
|
+
# @return [Array<PlayerGameStatGroup>] the stat groups
|
|
299
|
+
attribute :stats, PlayerGameStatGroup, collection: true
|
|
300
|
+
|
|
301
|
+
json do
|
|
302
|
+
map "stats", to: :stats
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
# Retrieves a player's stats for a specific game
|
|
306
|
+
#
|
|
307
|
+
# @api public
|
|
308
|
+
# @example Get player stats for a game
|
|
309
|
+
# MLB::PlayerGameStats.find(player: 660271, game: 745571)
|
|
310
|
+
# @example Get stats using Player and ScheduledGame objects
|
|
311
|
+
# MLB::PlayerGameStats.find(player: player, game: game)
|
|
312
|
+
# @param player [Integer, Player] the player ID or player object
|
|
313
|
+
# @param game [Integer, ScheduledGame] the game ID or game object
|
|
314
|
+
# @return [PlayerGameStats] the player's game stats
|
|
315
|
+
def self.find(player:, game:)
|
|
316
|
+
player_id = Utils.extract_id(player)
|
|
317
|
+
game_pk = game.respond_to?(:game_pk) ? game.game_pk : game
|
|
318
|
+
response = CLIENT.get("people/#{player_id}/stats/game/#{game_pk}")
|
|
319
|
+
from_json(response)
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# Returns the batting stats from the response
|
|
323
|
+
#
|
|
324
|
+
# @api public
|
|
325
|
+
# @example Get batting stats
|
|
326
|
+
# stats.batting #=> #<MLB::PlayerGameBattingStats>
|
|
327
|
+
# @return [PlayerGameBattingStats, nil] the batting stats
|
|
328
|
+
def batting
|
|
329
|
+
batting_group = stats.find { |s| s.group.eql?("hitting") }
|
|
330
|
+
split = batting_group&.splits&.first
|
|
331
|
+
return nil unless split
|
|
332
|
+
|
|
333
|
+
PlayerGameBattingStats.from_json(split.stat.to_json)
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
# Returns the pitching stats from the response
|
|
337
|
+
#
|
|
338
|
+
# @api public
|
|
339
|
+
# @example Get pitching stats
|
|
340
|
+
# stats.pitching #=> #<MLB::PlayerGamePitchingStats>
|
|
341
|
+
# @return [PlayerGamePitchingStats, nil] the pitching stats
|
|
342
|
+
def pitching
|
|
343
|
+
pitching_group = stats.find { |s| s.group.eql?("pitching") }
|
|
344
|
+
split = pitching_group&.splits&.first
|
|
345
|
+
return nil unless split
|
|
346
|
+
|
|
347
|
+
PlayerGamePitchingStats.from_json(split.stat.to_json)
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require "equalizer"
|
|
2
|
+
require "shale"
|
|
3
|
+
require_relative "stat_values"
|
|
4
|
+
require_relative "player"
|
|
5
|
+
require_relative "team"
|
|
6
|
+
require_relative "position"
|
|
7
|
+
|
|
8
|
+
module MLB
|
|
9
|
+
# Represents a player stat split
|
|
10
|
+
class PlayerStat < Shale::Mapper
|
|
11
|
+
include Equalizer.new(:player, :rank)
|
|
12
|
+
|
|
13
|
+
# @!attribute [rw] season
|
|
14
|
+
# Returns the season for this stat split
|
|
15
|
+
# @api public
|
|
16
|
+
# @example
|
|
17
|
+
# player_stat.season #=> "2024"
|
|
18
|
+
# @return [String] the season
|
|
19
|
+
attribute :season, Shale::Type::String
|
|
20
|
+
|
|
21
|
+
# @!attribute [rw] stat
|
|
22
|
+
# Returns the stat values
|
|
23
|
+
# @api public
|
|
24
|
+
# @example
|
|
25
|
+
# player_stat.stat.home_runs #=> 54
|
|
26
|
+
# @return [StatValues] the stat values
|
|
27
|
+
attribute :stat, StatValues
|
|
28
|
+
|
|
29
|
+
# @!attribute [rw] player
|
|
30
|
+
# Returns the player
|
|
31
|
+
# @api public
|
|
32
|
+
# @example
|
|
33
|
+
# player_stat.player.name #=> "Aaron Judge"
|
|
34
|
+
# @return [Player] the player
|
|
35
|
+
attribute :player, Player
|
|
36
|
+
|
|
37
|
+
# @!attribute [rw] team
|
|
38
|
+
# Returns the team
|
|
39
|
+
# @api public
|
|
40
|
+
# @example
|
|
41
|
+
# player_stat.team.name #=> "New York Yankees"
|
|
42
|
+
# @return [Team] the team
|
|
43
|
+
attribute :team, Team
|
|
44
|
+
|
|
45
|
+
# @!attribute [rw] rank
|
|
46
|
+
# Returns the rank in the stat leaderboard
|
|
47
|
+
# @api public
|
|
48
|
+
# @example
|
|
49
|
+
# player_stat.rank #=> 1
|
|
50
|
+
# @return [Integer] the rank
|
|
51
|
+
attribute :rank, Shale::Type::Integer
|
|
52
|
+
|
|
53
|
+
# @!attribute [rw] position
|
|
54
|
+
# Returns the player's position
|
|
55
|
+
# @api public
|
|
56
|
+
# @example
|
|
57
|
+
# player_stat.position.abbreviation #=> "RF"
|
|
58
|
+
# @return [Position] the position
|
|
59
|
+
attribute :position, Position
|
|
60
|
+
|
|
61
|
+
json do
|
|
62
|
+
map "season", to: :season
|
|
63
|
+
map "stat", to: :stat
|
|
64
|
+
map "player", to: :player
|
|
65
|
+
map "team", to: :team
|
|
66
|
+
map "rank", to: :rank
|
|
67
|
+
map "position", to: :position
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|