Class: MLB::PlayerGameStats
- Inherits:
-
Shale::Mapper
- Object
- Shale::Mapper
- MLB::PlayerGameStats
- Defined in:
- lib/mlb/player_game_stats.rb
Overview
Provides methods for fetching player game stats from the API
Instance Attribute Summary collapse
-
#stats ⇒ Array<PlayerGameStatGroup>
Returns the stat groups.
Class Method Summary collapse
-
.find(player:, game:) ⇒ PlayerGameStats
Retrieves a player’s stats for a specific game.
Instance Method Summary collapse
-
#batting ⇒ PlayerGameBattingStats?
Returns the batting stats from the response.
-
#pitching ⇒ PlayerGamePitchingStats?
Returns the pitching stats from the response.
Instance Attribute Details
#stats ⇒ Array<PlayerGameStatGroup>
Returns the stat groups
299 |
# File 'lib/mlb/player_game_stats.rb', line 299 attribute :stats, PlayerGameStatGroup, collection: true |
Class Method Details
.find(player:, game:) ⇒ PlayerGameStats
Retrieves a player’s stats for a specific game
315 316 317 318 319 320 |
# File 'lib/mlb/player_game_stats.rb', line 315 def self.find(player:, game:) player_id = Utils.extract_id(player) game_pk = game.respond_to?(:game_pk) ? game.game_pk : game response = CLIENT.get("people/#{player_id}/stats/game/#{game_pk}") from_json(response) end |
Instance Method Details
#batting ⇒ PlayerGameBattingStats?
Returns the batting stats from the response
328 329 330 331 332 333 334 |
# File 'lib/mlb/player_game_stats.rb', line 328 def batting batting_group = stats.find { |s| s.group.eql?("hitting") } split = batting_group&.splits&.first return nil unless split PlayerGameBattingStats.from_json(split.stat.to_json) end |
#pitching ⇒ PlayerGamePitchingStats?
Returns the pitching stats from the response
342 343 344 345 346 347 348 |
# File 'lib/mlb/player_game_stats.rb', line 342 def pitching pitching_group = stats.find { |s| s.group.eql?("pitching") } split = pitching_group&.splits&.first return nil unless split PlayerGamePitchingStats.from_json(split.stat.to_json) end |