Class: Sportradar::Api::Football::Ncaafb::Drive

Inherits:
Drive
  • Object
show all
Defined in:
lib/sportradar/api/football/ncaafb/drive.rb

Instance Attribute Summary

Attributes inherited from Drive

#api, #id, #penalty_yards, #quarter, #response, #scoring_drive, #sequence, #start_reason, #team

Instance Method Summary collapse

Methods inherited from Drive

#end_reason_possibilities, #events, #halftime?, #initialize, new, #normalized_end_reason, #overtime?, #plays

Methods inherited from Data

#all_attributes, #attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data

Constructor Details

This class inherits a constructor from Sportradar::Api::Football::Drive

Instance Method Details

#durationObject



28
29
30
31
# File 'lib/sportradar/api/football/ncaafb/drive.rb', line 28

def duration
  mm, ss = duration_seconds.divmod(60)
  "#{mm}:#{ss.to_s.rjust(2, '0')}"
end

#duration_secondsObject



18
19
20
21
22
23
24
25
26
# File 'lib/sportradar/api/football/ncaafb/drive.rb', line 18

def duration_seconds
  start_time = plays.first&.clock_seconds
  end_time   = plays.last&.clock_seconds
  if end_time > start_time
    start_time + 900 - end_time
  else
    start_time - end_time
  end
end

#end_reasonObject



33
34
35
36
37
38
39
40
41
# File 'lib/sportradar/api/football/ncaafb/drive.rb', line 33

def end_reason
  ending = plays.reverse_each.detect {|pl| !pl.timeout? && pl.play_type != 'penalty' }&.parsed_ending
  last_play = plays.reverse_each.detect {|pl| !pl.timeout? }
  ending ||= if last_play.down == 4 && last_play.yards < last_play.yfd
    'Downs'
  else
    'UNKNOWN'
  end
end

#first_downsObject



43
44
45
# File 'lib/sportradar/api/football/ncaafb/drive.rb', line 43

def first_downs
  plays.count(&:made_first_down?)
end

#gainObject



60
61
62
# File 'lib/sportradar/api/football/ncaafb/drive.rb', line 60

def gain
  Array(plays.select(&:counted_play?)).map(&:yards).inject(:+).to_i
end

#handle_plays_and_events(data, **opts) ⇒ Object



51
52
53
54
# File 'lib/sportradar/api/football/ncaafb/drive.rb', line 51

def handle_plays_and_events(data, **opts)
  create_data(@plays_hash,  data['actions'],  klass: Play,  api: api, drive: self) if data['actions']
  create_data(@events_hash, data['events'],   klass: Event, api: api, drive: self) if data['events']
end

#over?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/sportradar/api/football/ncaafb/drive.rb', line 47

def over?
  (end_reason != 'UNKNOWN') || (overtime? && ['End of Quarter', 'End of Game'].include?(plays.last&.description))
end

#play_countObject



56
57
58
# File 'lib/sportradar/api/football/ncaafb/drive.rb', line 56

def play_count
  plays.count(&:counted_play?)
end

#update(data, **opts) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/sportradar/api/football/ncaafb/drive.rb', line 9

def update(data, **opts)
  super.tap {
    if opts[:game]
      game_drives = opts[:game].drives
      @sequence = (game_drives.index(self) || game_drives.size) + 1
    end
  }
end