Class: Sportradar::Nfl::Models::Drive

Inherits:
Object
  • Object
show all
Defined in:
lib/sportradar/nfl/models/drive.rb

Overview

NOTE: This data structure isn’t techincially a single drive as due to the way Sportradar structures the play by play data and how it will be parsed a drive could be separated into two sets of info and plays by a TV timeout or the end of the quarter. The data/drive will continue using the same drive id in subsequent action data.

Therefore, it would be incorrect to count the number of plays in the drive to get the play count.

In addition, the drive data can contain actions/plays for other teams, such as when one team kicks off, then a tvtimeout, then the offensive team has their first play.

To get the offensive plays, you need to compare the drive’s team with the play’s side.

Instance Method Summary collapse

Constructor Details

#initialize(quarter:, attributes:) ⇒ Drive

Returns a new instance of Drive.



20
21
22
23
# File 'lib/sportradar/nfl/models/drive.rb', line 20

def initialize(quarter:, attributes:)
  @quarter = quarter
  @attributes = attributes
end

Instance Method Details

#actionsObject



57
58
59
# File 'lib/sportradar/nfl/models/drive.rb', line 57

def actions
  @actions ||= @attributes.dig('actions') || []
end

#clockObject



41
42
43
# File 'lib/sportradar/nfl/models/drive.rb', line 41

def clock
  @attributes['clock'] || '0'
end

#eventsObject



65
66
67
# File 'lib/sportradar/nfl/models/drive.rb', line 65

def events
  @events || build_events || []
end

#game_idObject



29
30
31
# File 'lib/sportradar/nfl/models/drive.rb', line 29

def game_id
  quarter.game_id
end

#idObject



45
46
47
# File 'lib/sportradar/nfl/models/drive.rb', line 45

def id
  @attributes['id']
end

#playsObject



61
62
63
# File 'lib/sportradar/nfl/models/drive.rb', line 61

def plays
  @plays || build_plays || []
end

#quarterObject



33
34
35
# File 'lib/sportradar/nfl/models/drive.rb', line 33

def quarter
  @quarter
end

#quarter_numberObject



37
38
39
# File 'lib/sportradar/nfl/models/drive.rb', line 37

def quarter_number
  @quarter.number
end

#teamObject



49
50
51
# File 'lib/sportradar/nfl/models/drive.rb', line 49

def team
  @attributes['team']
end

#to_sObject



25
26
27
# File 'lib/sportradar/nfl/models/drive.rb', line 25

def to_s
  "#{quarter.to_s} #{clock}"
end

#typeObject



53
54
55
# File 'lib/sportradar/nfl/models/drive.rb', line 53

def type
  @attributes['type']
end