Class: SportsDataApi::Nfl::PlayByPlays

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sports_data_api/nfl/play_by_plays.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pbp_events) ⇒ PlayByPlays

Returns a new instance of PlayByPlays.



7
8
9
10
11
12
13
14
15
# File 'lib/sports_data_api/nfl/play_by_plays.rb', line 7

def initialize(pbp_events)
  @events = pbp_events.map do |pbp_event|
    if pbp_event["type"] == "event"
      Event.new(pbp_event)
    elsif pbp_event["type"] == "drive"
      Drive.new(pbp_event)
    end
  end
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



5
6
7
# File 'lib/sports_data_api/nfl/play_by_plays.rb', line 5

def events
  @events
end

Instance Method Details

#each(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/sports_data_api/nfl/play_by_plays.rb', line 17

def each &block
  @events.each do |event|
    if block_given?
      block.call event
    else
      yield event
    end
  end
end