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,173 @@
1
+ require "shale"
2
+ require_relative "sport"
3
+
4
+ module MLB
5
+ # Represents game pace statistics
6
+ class GamePaceStats < Shale::Mapper
7
+ # @!attribute [rw] hits_per_9inn
8
+ # Returns hits per 9 innings
9
+ # @api public
10
+ # @example
11
+ # stats.hits_per_9inn #=> 16.63
12
+ # @return [Float] the hits per 9 innings
13
+ attribute :hits_per_9inn, Shale::Type::Float
14
+
15
+ # @!attribute [rw] runs_per_9inn
16
+ # Returns runs per 9 innings
17
+ # @api public
18
+ # @example
19
+ # stats.runs_per_9inn #=> 8.91
20
+ # @return [Float] the runs per 9 innings
21
+ attribute :runs_per_9inn, Shale::Type::Float
22
+
23
+ # @!attribute [rw] pitches_per_9inn
24
+ # Returns pitches per 9 innings
25
+ # @api public
26
+ # @example
27
+ # stats.pitches_per_9inn #=> 296.2
28
+ # @return [Float] the pitches per 9 innings
29
+ attribute :pitches_per_9inn, Shale::Type::Float
30
+
31
+ # @!attribute [rw] hits_per_game
32
+ # Returns hits per game
33
+ # @api public
34
+ # @example
35
+ # stats.hits_per_game #=> 16.39
36
+ # @return [Float] the hits per game
37
+ attribute :hits_per_game, Shale::Type::Float
38
+
39
+ # @!attribute [rw] runs_per_game
40
+ # Returns runs per game
41
+ # @api public
42
+ # @example
43
+ # stats.runs_per_game #=> 8.79
44
+ # @return [Float] the runs per game
45
+ attribute :runs_per_game, Shale::Type::Float
46
+
47
+ # @!attribute [rw] pitches_per_game
48
+ # Returns pitches per game
49
+ # @api public
50
+ # @example
51
+ # stats.pitches_per_game #=> 292.1
52
+ # @return [Float] the pitches per game
53
+ attribute :pitches_per_game, Shale::Type::Float
54
+
55
+ # @!attribute [rw] total_games
56
+ # Returns total games
57
+ # @api public
58
+ # @example
59
+ # stats.total_games #=> 2429
60
+ # @return [Integer] the total games
61
+ attribute :total_games, Shale::Type::Integer
62
+
63
+ # @!attribute [rw] total_innings_played
64
+ # Returns total innings played
65
+ # @api public
66
+ # @example
67
+ # stats.total_innings_played #=> 21626.5
68
+ # @return [Float] the total innings
69
+ attribute :total_innings_played, Shale::Type::Float
70
+
71
+ # @!attribute [rw] total_hits
72
+ # Returns total hits
73
+ # @api public
74
+ # @example
75
+ # stats.total_hits #=> 39823
76
+ # @return [Integer] the total hits
77
+ attribute :total_hits, Shale::Type::Integer
78
+
79
+ # @!attribute [rw] total_runs
80
+ # Returns total runs
81
+ # @api public
82
+ # @example
83
+ # stats.total_runs #=> 21343
84
+ # @return [Integer] the total runs
85
+ attribute :total_runs, Shale::Type::Integer
86
+
87
+ # @!attribute [rw] total_pitches
88
+ # Returns total pitches
89
+ # @api public
90
+ # @example
91
+ # stats.total_pitches #=> 709511
92
+ # @return [Integer] the total pitches
93
+ attribute :total_pitches, Shale::Type::Integer
94
+
95
+ # @!attribute [rw] time_per_game
96
+ # Returns average time per game
97
+ # @api public
98
+ # @example
99
+ # stats.time_per_game #=> "02:38:44"
100
+ # @return [String] the time per game
101
+ attribute :time_per_game, Shale::Type::String
102
+
103
+ # @!attribute [rw] time_per_pitch
104
+ # Returns average time per pitch
105
+ # @api public
106
+ # @example
107
+ # stats.time_per_pitch #=> "00:00:32"
108
+ # @return [String] the time per pitch
109
+ attribute :time_per_pitch, Shale::Type::String
110
+
111
+ # @!attribute [rw] season
112
+ # Returns the season
113
+ # @api public
114
+ # @example
115
+ # stats.season #=> "2024"
116
+ # @return [String] the season
117
+ attribute :season, Shale::Type::String
118
+
119
+ # @!attribute [rw] sport
120
+ # Returns the sport
121
+ # @api public
122
+ # @example
123
+ # stats.sport #=> #<MLB::Sport>
124
+ # @return [Sport] the sport
125
+ attribute :sport, Sport
126
+
127
+ json do
128
+ map "hitsPer9Inn", to: :hits_per_9inn
129
+ map "runsPer9Inn", to: :runs_per_9inn
130
+ map "pitchesPer9Inn", to: :pitches_per_9inn
131
+ map "hitsPerGame", to: :hits_per_game
132
+ map "runsPerGame", to: :runs_per_game
133
+ map "pitchesPerGame", to: :pitches_per_game
134
+ map "totalGames", to: :total_games
135
+ map "totalInningsPlayed", to: :total_innings_played
136
+ map "totalHits", to: :total_hits
137
+ map "totalRuns", to: :total_runs
138
+ map "totalPitches", to: :total_pitches
139
+ map "timePerGame", to: :time_per_game
140
+ map "timePerPitch", to: :time_per_pitch
141
+ map "season", to: :season
142
+ map "sport", to: :sport
143
+ end
144
+ end
145
+
146
+ # Provides methods for fetching game pace data from the API
147
+ class GamePace < Shale::Mapper
148
+ # @!attribute [rw] sports
149
+ # Returns the sports game pace data
150
+ # @api public
151
+ # @example
152
+ # game_pace.sports #=> [#<MLB::GamePaceStats>, ...]
153
+ # @return [Array<GamePaceStats>] the sports data
154
+ attribute :sports, GamePaceStats, collection: true
155
+
156
+ json do
157
+ map "sports", to: :sports
158
+ end
159
+
160
+ # Retrieves game pace statistics for a season
161
+ #
162
+ # @api public
163
+ # @example Get game pace for 2024
164
+ # MLB::GamePace.find(season: 2024)
165
+ # @param season [Integer, nil] the season year (defaults to current year)
166
+ # @return [GamePaceStats] the game pace stats for MLB
167
+ def self.find(season: nil)
168
+ season ||= Utils.current_season
169
+ response = CLIENT.get("gamePace?#{Utils.build_query(season:)}")
170
+ from_json(response).sports.first
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,94 @@
1
+ require "equalizer"
2
+ require "shale"
3
+
4
+ module MLB
5
+ # Represents a game status
6
+ class GameStatus < Shale::Mapper
7
+ include Equalizer.new(:status_code)
8
+
9
+ FINAL = "Final".freeze
10
+ LIVE = "Live".freeze
11
+ PREVIEW = "Preview".freeze
12
+
13
+ # @!attribute [rw] abstract_game_state
14
+ # Returns the high-level game state
15
+ # @api public
16
+ # @example
17
+ # game_status.abstract_game_state #=> "Final"
18
+ # @return [String] the high-level game state
19
+ attribute :abstract_game_state, Shale::Type::String
20
+
21
+ # @!attribute [rw] coded_game_state
22
+ # Returns the coded game state
23
+ # @api public
24
+ # @example
25
+ # game_status.coded_game_state #=> "F"
26
+ # @return [String] the coded game state
27
+ attribute :coded_game_state, Shale::Type::String
28
+
29
+ # @!attribute [rw] detailed_state
30
+ # Returns the detailed game state
31
+ # @api public
32
+ # @example
33
+ # game_status.detailed_state #=> "Final"
34
+ # @return [String] the detailed game state
35
+ attribute :detailed_state, Shale::Type::String
36
+
37
+ # @!attribute [rw] status_code
38
+ # Returns the status code
39
+ # @api public
40
+ # @example
41
+ # game_status.status_code #=> "F"
42
+ # @return [String] the status code
43
+ attribute :status_code, Shale::Type::String
44
+
45
+ # @!attribute [rw] abstract_game_code
46
+ # Returns the abstract game code
47
+ # @api public
48
+ # @example
49
+ # game_status.abstract_game_code #=> "F"
50
+ # @return [String] the abstract game code
51
+ attribute :abstract_game_code, Shale::Type::String
52
+
53
+ # @!attribute [rw] reason
54
+ # Returns the reason for the status
55
+ # @api public
56
+ # @example
57
+ # game_status.reason #=> "Rain"
58
+ # @return [String] the reason for the status
59
+ attribute :reason, Shale::Type::String
60
+
61
+ # Returns whether the game is final (completed)
62
+ #
63
+ # @api public
64
+ # @example
65
+ # game_status.final? #=> true
66
+ # @return [Boolean] whether the game is final
67
+ def final? = abstract_game_state.eql?(FINAL)
68
+
69
+ # Returns whether the game is live (in progress)
70
+ #
71
+ # @api public
72
+ # @example
73
+ # game_status.live? #=> false
74
+ # @return [Boolean] whether the game is live
75
+ def live? = abstract_game_state.eql?(LIVE)
76
+
77
+ # Returns whether the game is in preview (not yet started)
78
+ #
79
+ # @api public
80
+ # @example
81
+ # game_status.preview? #=> false
82
+ # @return [Boolean] whether the game is in preview
83
+ def preview? = abstract_game_state.eql?(PREVIEW)
84
+
85
+ json do
86
+ map "abstractGameState", to: :abstract_game_state
87
+ map "codedGameState", to: :coded_game_state
88
+ map "detailedState", to: :detailed_state
89
+ map "statusCode", to: :status_code
90
+ map "abstractGameCode", to: :abstract_game_code
91
+ map "reason", to: :reason
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "collection"
2
+ require_relative "game_status"
3
+
4
+ module MLB
5
+ # Provides methods for fetching game statuses from the API
6
+ #
7
+ # @example Fetch all game statuses
8
+ # MLB::GameStatuses.all #=> [#<MLB::GameStatus>, ...]
9
+ class GameStatuses < Collection
10
+ collection endpoint: "gameStatus", item_type: GameStatus, collection_name: :game_statuses
11
+ end
12
+ end
@@ -0,0 +1,98 @@
1
+ require_relative "id_description_type"
2
+
3
+ module MLB
4
+ # Represents a game type (e.g., Regular Season, Postseason, Spring Training)
5
+ class GameType < IdDescriptionType
6
+ # Game type: Regular Season
7
+ TYPE_REGULAR = "R".freeze
8
+ # Game type: Spring Training
9
+ TYPE_SPRING = "S".freeze
10
+ # Game type: Exhibition
11
+ TYPE_EXHIBITION = "E".freeze
12
+ # Game type: All-Star Game
13
+ TYPE_ALL_STAR = "A".freeze
14
+ # Game type: Wild Card
15
+ TYPE_WILD_CARD = "F".freeze
16
+ # Game type: Division Series
17
+ TYPE_DIVISION = "D".freeze
18
+ # Game type: League Championship Series
19
+ TYPE_LCS = "L".freeze
20
+ # Game type: World Series
21
+ TYPE_WORLD_SERIES = "W".freeze
22
+ # Game type codes that indicate postseason games
23
+ POSTSEASON_TYPES = %w[F D L W].freeze
24
+
25
+ # Returns whether this is a regular season game type
26
+ #
27
+ # @api public
28
+ # @example
29
+ # game_type.regular_season? #=> true
30
+ # @return [Boolean] whether this is a regular season game type
31
+ def regular_season? = id.eql?(TYPE_REGULAR)
32
+
33
+ # Returns whether this is a spring training game type
34
+ #
35
+ # @api public
36
+ # @example
37
+ # game_type.spring_training? #=> false
38
+ # @return [Boolean] whether this is a spring training game type
39
+ def spring_training? = id.eql?(TYPE_SPRING)
40
+
41
+ # Returns whether this is an exhibition game type
42
+ #
43
+ # @api public
44
+ # @example
45
+ # game_type.exhibition? #=> false
46
+ # @return [Boolean] whether this is an exhibition game type
47
+ def exhibition? = id.eql?(TYPE_EXHIBITION)
48
+
49
+ # Returns whether this is an All-Star game type
50
+ #
51
+ # @api public
52
+ # @example
53
+ # game_type.all_star? #=> false
54
+ # @return [Boolean] whether this is an All-Star game type
55
+ def all_star? = id.eql?(TYPE_ALL_STAR)
56
+
57
+ # Returns whether this is a Wild Card game type
58
+ #
59
+ # @api public
60
+ # @example
61
+ # game_type.wild_card? #=> false
62
+ # @return [Boolean] whether this is a Wild Card game type
63
+ def wild_card? = id.eql?(TYPE_WILD_CARD)
64
+
65
+ # Returns whether this is a Division Series game type
66
+ #
67
+ # @api public
68
+ # @example
69
+ # game_type.division_series? #=> false
70
+ # @return [Boolean] whether this is a Division Series game type
71
+ def division_series? = id.eql?(TYPE_DIVISION)
72
+
73
+ # Returns whether this is a League Championship Series game type
74
+ #
75
+ # @api public
76
+ # @example
77
+ # game_type.lcs? #=> false
78
+ # @return [Boolean] whether this is a League Championship Series game type
79
+ def lcs? = id.eql?(TYPE_LCS)
80
+
81
+ # Returns whether this is a World Series game type
82
+ #
83
+ # @api public
84
+ # @example
85
+ # game_type.world_series? #=> false
86
+ # @return [Boolean] whether this is a World Series game type
87
+ def world_series? = id.eql?(TYPE_WORLD_SERIES)
88
+
89
+ # Returns whether this is a postseason game type
90
+ #
91
+ # @api public
92
+ # @example
93
+ # game_type.postseason? #=> false
94
+ # @return [Boolean] whether this is a postseason game type
95
+ # mutant:disable - .to_s is for type safety; include?(nil) returns false anyway
96
+ def postseason? = POSTSEASON_TYPES.include?(id.to_s)
97
+ end
98
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "collection"
2
+ require_relative "game_type"
3
+
4
+ module MLB
5
+ # Provides methods for fetching game types from the API
6
+ #
7
+ # @example Fetch all game types
8
+ # MLB::GameTypes.all #=> [#<MLB::GameType>, ...]
9
+ class GameTypes < Collection
10
+ collection endpoint: "gameTypes", item_type: GameType, collection_name: :game_types
11
+ end
12
+ end
@@ -1,16 +1,34 @@
1
- require "equalizer"
2
- require "shale"
1
+ require_relative "code_description_type"
3
2
 
4
3
  module MLB
5
- class Handedness < Shale::Mapper
6
- include Equalizer.new(:code)
4
+ # Represents handedness (batting or throwing side)
5
+ class Handedness < CodeDescriptionType
6
+ LEFT = "L".freeze
7
+ RIGHT = "R".freeze
8
+ SWITCH = "S".freeze
7
9
 
8
- attribute :code, Shale::Type::String
9
- attribute :description, Shale::Type::String
10
+ # Returns whether this is left-handed
11
+ #
12
+ # @api public
13
+ # @example
14
+ # handedness.left? #=> true
15
+ # @return [Boolean] whether this is left-handed
16
+ def left? = code.eql?(LEFT)
10
17
 
11
- json do
12
- map "code", to: :code
13
- map "description", to: :description
14
- end
18
+ # Returns whether this is right-handed
19
+ #
20
+ # @api public
21
+ # @example
22
+ # handedness.right? #=> false
23
+ # @return [Boolean] whether this is right-handed
24
+ def right? = code.eql?(RIGHT)
25
+
26
+ # Returns whether this is switch (both sides)
27
+ #
28
+ # @api public
29
+ # @example
30
+ # handedness.switch? #=> false
31
+ # @return [Boolean] whether this is switch
32
+ def switch? = code.eql?(SWITCH)
15
33
  end
16
34
  end
@@ -0,0 +1,121 @@
1
+ require "equalizer"
2
+ require "shale"
3
+ require_relative "team"
4
+
5
+ module MLB
6
+ # Represents a high/low stat result
7
+ class HighLowResult < Shale::Mapper
8
+ include Equalizer.new(:team, :date, :rank)
9
+
10
+ # @!attribute [rw] season
11
+ # Returns the season
12
+ # @api public
13
+ # @example
14
+ # result.season #=> "2024"
15
+ # @return [String] the season
16
+ attribute :season, Shale::Type::String
17
+
18
+ # @!attribute [rw] team
19
+ # Returns the team
20
+ # @api public
21
+ # @example
22
+ # result.team #=> #<MLB::Team>
23
+ # @return [Team] the team
24
+ attribute :team, Team
25
+
26
+ # @!attribute [rw] opponent
27
+ # Returns the opponent team
28
+ # @api public
29
+ # @example
30
+ # result.opponent #=> #<MLB::Team>
31
+ # @return [Team] the opponent
32
+ attribute :opponent, Team
33
+
34
+ # @!attribute [rw] date
35
+ # Returns the date
36
+ # @api public
37
+ # @example
38
+ # result.date #=> "2024-06-06"
39
+ # @return [String] the date
40
+ attribute :date, Shale::Type::String
41
+
42
+ # @!attribute [rw] is_home
43
+ # Returns whether the team was at home
44
+ # @api public
45
+ # @example
46
+ # result.home? #=> false
47
+ # @return [Boolean] whether at home
48
+ attribute :is_home, Shale::Type::Boolean
49
+
50
+ # @!attribute [rw] rank
51
+ # Returns the rank
52
+ # @api public
53
+ # @example
54
+ # result.rank #=> 1
55
+ # @return [Integer] the rank
56
+ attribute :rank, Shale::Type::Integer
57
+
58
+ # Returns whether the team was at home
59
+ #
60
+ # @api public
61
+ # @example
62
+ # result.home? #=> false
63
+ # @return [Boolean] whether at home
64
+ def home?
65
+ is_home
66
+ end
67
+
68
+ json do
69
+ map "season", to: :season
70
+ map "team", to: :team
71
+ map "opponent", to: :opponent
72
+ map "date", to: :date
73
+ map "isHome", to: :is_home
74
+ map "rank", to: :rank
75
+ end
76
+ end
77
+
78
+ # Represents a high/low group
79
+ class HighLowGroup < Shale::Mapper
80
+ # @!attribute [rw] splits
81
+ # Returns the stat splits
82
+ # @api public
83
+ # @example
84
+ # group.splits #=> [#<MLB::HighLowResult>, ...]
85
+ # @return [Array<HighLowResult>] the splits
86
+ attribute :splits, HighLowResult, collection: true
87
+
88
+ json do
89
+ map "splits", to: :splits
90
+ end
91
+ end
92
+
93
+ # Provides methods for fetching high/low stats from the API
94
+ class HighLow < Shale::Mapper
95
+ # @!attribute [rw] high_low_results
96
+ # Returns the high/low results
97
+ # @api public
98
+ # @example
99
+ # high_low.high_low_results #=> [#<MLB::HighLowGroup>, ...]
100
+ # @return [Array<HighLowGroup>] the results
101
+ attribute :high_low_results, HighLowGroup, collection: true
102
+
103
+ json do
104
+ map "highLowResults", to: :high_low_results
105
+ end
106
+
107
+ # Retrieves high/low stats for teams
108
+ #
109
+ # @api public
110
+ # @example Get high/low stats for teams
111
+ # MLB::HighLow.find(org_type: "team", season: 2024)
112
+ # @param org_type [String] the organization type (team, league, sport)
113
+ # @param season [Integer, nil] the season year (defaults to current year)
114
+ # @return [Array<HighLowResult>] the high/low results
115
+ def self.find(org_type:, season: nil)
116
+ season ||= Utils.current_season
117
+ response = CLIENT.get("highLow/#{org_type}?#{Utils.build_query(season:)}")
118
+ from_json(response).high_low_results.flat_map(&:splits)
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "collection"
2
+ require_relative "hit_trajectory"
3
+
4
+ module MLB
5
+ # Provides methods for fetching hit trajectories from the API
6
+ #
7
+ # @example Fetch all hit trajectories
8
+ # MLB::HitTrajectories.all #=> [#<MLB::HitTrajectory>, ...]
9
+ class HitTrajectories < Collection
10
+ collection endpoint: "hitTrajectories", item_type: HitTrajectory, collection_name: :hit_trajectories
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "code_description_type"
2
+
3
+ module MLB
4
+ # Represents a hit trajectory type (e.g., Line Drive, Fly Ball, Ground Ball)
5
+ class HitTrajectory < CodeDescriptionType; end
6
+ end