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

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

Direct Known Subclasses

Ncaafb::Drive, Nfl::Drive

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#initialize(data, **opts) ⇒ Drive

Returns a new instance of Drive.



15
16
17
18
19
20
21
22
# File 'lib/sportradar/api/football/drive.rb', line 15

def initialize(data, **opts)
  @id            = data["id"]
  @api           = opts[:api]
  @plays_hash    = {}
  @events_hash   = {}

  update(data, **opts)
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def api
  @api
end

#durationObject

Returns the value of attribute duration.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def duration
  @duration
end

#end_reasonObject

Returns the value of attribute end_reason.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def end_reason
  @end_reason
end

#first_downsObject

Returns the value of attribute first_downs.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def first_downs
  @first_downs
end

#gainObject

Returns the value of attribute gain.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def gain
  @gain
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def id
  @id
end

#penalty_yardsObject

Returns the value of attribute penalty_yards.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def penalty_yards
  @penalty_yards
end

#play_countObject

Returns the value of attribute play_count.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def play_count
  @play_count
end

#quarterObject

Returns the value of attribute quarter.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def quarter
  @quarter
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def response
  @response
end

#scoring_driveObject

Returns the value of attribute scoring_drive.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def scoring_drive
  @scoring_drive
end

#sequenceObject

Returns the value of attribute sequence.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def sequence
  @sequence
end

#start_reasonObject

Returns the value of attribute start_reason.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def start_reason
  @start_reason
end

#teamObject

Returns the value of attribute team.



5
6
7
# File 'lib/sportradar/api/football/drive.rb', line 5

def team
  @team
end

Class Method Details

.new(data, **opts) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/sportradar/api/football/drive.rb', line 7

def self.new(data, **opts)
  if data['type'] == 'event'
    Event.new(data, **opts)
  else
    super
  end
end

Instance Method Details

#end_reason_possibilitiesObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/sportradar/api/football/drive.rb', line 69

def end_reason_possibilities
  [
    'UNKNOWN',
    'Touchdown',
    'Safety',
    'Field Goal',
    'Missed FG',
    'Blocked FG',
    'Blocked FG, Downs',
    'Blocked FG, Safety',
    'Punt',
    'Blocked Punt',
    'Blocked Punt, Downs',
    'Blocked Punt, Safety',
    'Downs',
    'Interception',
    'Fumble',
    'Fumble, Safety',
    'Muffed FG',
    'Muffed Punt',
    'Muffed Kickoff',
    'Kickoff',
    'Own Kickoff',
    'Onside Kick',
    'Kickoff, No Play',
    'End of Half',
    'End of Game',
  ]
end

#eventsObject



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

def events
  @events_hash.values
end

#halftime?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/sportradar/api/football/drive.rb', line 53

def halftime?
  self.end_reason == 'End of Half'
end

#normalized_end_reasonObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/sportradar/api/football/drive.rb', line 98

def normalized_end_reason
  case end_reason
  when 'Touchdown', :pat
    'Touchdown'
  when 'Field Goal', 'Missed FG', "Blocked FG, Downs", 'Muffed FG', :fg
    'Field Goal'
  when 'Downs'
    'Downs'
  when 'Interception', 'Fumble', :fumble, :interception
    'Turnover'
  when 'Punt', 'Blocked Punt, Downs', 'Blocked Punt, Safety', :punt
    'Punt'
  when 'End of Half', :end_of_half
    'End of Half'
  when 'End of Game', :end_of_game
    'End of Game'
  when 'Safety', 'Blocked FG, Safety'
    'Safety'
  else
    'Other'
  end
end

#over?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/sportradar/api/football/drive.rb', line 65

def over?
  end_reason != 'UNKNOWN' && !end_reason.nil? # && !plays.last.parsed_ending # FIXME - maybe fix this. sim games have inconsistent data
end

#overtime?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/sportradar/api/football/drive.rb', line 49

def overtime?
  @overtime
end

#playsObject



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

def plays
  @plays_hash.values
end

#update(data, **opts) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sportradar/api/football/drive.rb', line 24

def update(data, **opts)
  @response       = data
  @type           = data['type']
  @team           = data['team']
  @clock          = data['clock']
  @overtime       = !!opts[:quarter]&.overtime? || @overtime

  @sequence       = data["sequence"]
  @start_reason   = data["start_reason"]
  @end_reason     = data["end_reason"]
  @play_count     = data["play_count"]
  @duration       = data["duration"]
  @first_downs    = data["first_downs"]
  @gain           = data["gain"]
  @penalty_yards  = data["penalty_yards"]
  @scoring_drive  = data["scoring_drive"]

  @quarter_data = data['quarter']
  @team_data    = data['team']

  handle_plays_and_events(data, **opts)

  self
end