Class: MLB::PlayByPlay

Inherits:
Shale::Mapper
  • Object
show all
Defined in:
lib/mlb/play_by_play.rb

Overview

Provides methods for fetching play-by-play data from the API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#all_playsArray<Play>

Returns all plays in the game

Examples:

pbp.all_plays #=> [#<MLB::Play>, ...]

Returns:

  • (Array<Play>)

    all plays



13
# File 'lib/mlb/play_by_play.rb', line 13

attribute :all_plays, Play, collection: true

#current_playPlay

Returns the current play

Examples:

pbp.current_play #=> #<MLB::Play>

Returns:

  • (Play)

    the current play



21
# File 'lib/mlb/play_by_play.rb', line 21

attribute :current_play, Play

#scoring_playsArray<Integer>

Returns indices of scoring plays

Examples:

pbp.scoring_plays #=> [5, 12, 23]

Returns:

  • (Array<Integer>)

    scoring play indices



29
# File 'lib/mlb/play_by_play.rb', line 29

attribute :scoring_plays, Shale::Type::Integer, collection: true

Class Method Details

.find(game:) ⇒ PlayByPlay

Retrieves play-by-play data for a game

Examples:

Get play-by-play for a game

MLB::PlayByPlay.find(game: 745571)

Get play-by-play for a scheduled game

MLB::PlayByPlay.find(game: ScheduledGame.new(game_pk: 745571))

Parameters:

Returns:



46
47
48
49
50
# File 'lib/mlb/play_by_play.rb', line 46

def self.find(game:)
  game_pk = game.respond_to?(:game_pk) ? game.game_pk : game
  response = CLIENT.get("game/#{game_pk}/playByPlay")
  from_json(response)
end