class Sportradar::Nfl::Models::Drive
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.
Public Class Methods
new(quarter:, attributes:)
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 20 def initialize(quarter:, attributes:) @quarter = quarter @attributes = attributes end
Public Instance Methods
actions()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 57 def actions @actions ||= @attributes.dig('actions') || [] end
clock()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 41 def clock @attributes['clock'] || '0' end
events()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 65 def events @events || build_events || [] end
game_id()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 29 def game_id quarter.game_id end
id()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 45 def id @attributes['id'] end
plays()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 61 def plays @plays || build_plays || [] end
quarter()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 33 def quarter @quarter end
quarter_number()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 37 def quarter_number @quarter.number end
team()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 49 def team @attributes['team'] end
to_s()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 25 def to_s "#{quarter.to_s} #{clock}" end
type()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 53 def type @attributes['type'] end
Private Instance Methods
build_events()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 79 def build_events actions.each_with_object([]) do |action, _events| if action['type'] != 'play' _events << Models::Event.new(drive: self, attributes: action) end end end
build_plays()
click to toggle source
# File lib/sportradar/nfl/models/drive.rb, line 71 def build_plays actions.each_with_object([]) do |action, _plays| if action['type'] == 'play' _plays << Models::Play.new(drive: self, attributes: action) end end end