Class: Sportradar::Api::Football::Drive
- Defined in:
- lib/sportradar/api/football/drive.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api ⇒ Object
Returns the value of attribute api.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#end_reason ⇒ Object
Returns the value of attribute end_reason.
-
#first_downs ⇒ Object
Returns the value of attribute first_downs.
-
#gain ⇒ Object
Returns the value of attribute gain.
-
#id ⇒ Object
Returns the value of attribute id.
-
#penalty_yards ⇒ Object
Returns the value of attribute penalty_yards.
-
#play_count ⇒ Object
Returns the value of attribute play_count.
-
#quarter ⇒ Object
Returns the value of attribute quarter.
-
#response ⇒ Object
Returns the value of attribute response.
-
#scoring_drive ⇒ Object
Returns the value of attribute scoring_drive.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#start_reason ⇒ Object
Returns the value of attribute start_reason.
-
#team ⇒ Object
Returns the value of attribute team.
Class Method Summary collapse
Instance Method Summary collapse
- #end_reason_possibilities ⇒ Object
- #events ⇒ Object
- #halftime? ⇒ Boolean
-
#initialize(data, **opts) ⇒ Drive
constructor
A new instance of Drive.
- #normalized_end_reason ⇒ Object
- #over? ⇒ Boolean
- #overtime? ⇒ Boolean
- #plays ⇒ Object
- #update(data, **opts) ⇒ Object
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
#api ⇒ Object
Returns the value of attribute api.
5 6 7 |
# File 'lib/sportradar/api/football/drive.rb', line 5 def api @api end |
#duration ⇒ Object
Returns the value of attribute duration.
5 6 7 |
# File 'lib/sportradar/api/football/drive.rb', line 5 def duration @duration end |
#end_reason ⇒ Object
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_downs ⇒ Object
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 |
#gain ⇒ Object
Returns the value of attribute gain.
5 6 7 |
# File 'lib/sportradar/api/football/drive.rb', line 5 def gain @gain end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/football/drive.rb', line 5 def id @id end |
#penalty_yards ⇒ Object
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_count ⇒ Object
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 |
#quarter ⇒ Object
Returns the value of attribute quarter.
5 6 7 |
# File 'lib/sportradar/api/football/drive.rb', line 5 def quarter @quarter end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/football/drive.rb', line 5 def response @response end |
#scoring_drive ⇒ Object
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 |
#sequence ⇒ Object
Returns the value of attribute sequence.
5 6 7 |
# File 'lib/sportradar/api/football/drive.rb', line 5 def sequence @sequence end |
#start_reason ⇒ Object
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 |
#team ⇒ Object
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
Instance Method Details
#end_reason_possibilities ⇒ Object
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 |
#events ⇒ Object
61 62 63 |
# File 'lib/sportradar/api/football/drive.rb', line 61 def events @events_hash.values end |
#halftime? ⇒ Boolean
53 54 55 |
# File 'lib/sportradar/api/football/drive.rb', line 53 def halftime? self.end_reason == 'End of Half' end |
#normalized_end_reason ⇒ Object
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
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
49 50 51 |
# File 'lib/sportradar/api/football/drive.rb', line 49 def overtime? @overtime end |
#plays ⇒ Object
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 |