Class: Sportradar::Api::Football::Play
- Defined in:
- lib/sportradar/api/football/play.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#alt_description ⇒ Object
Returns the value of attribute alt_description.
-
#away_points ⇒ Object
Returns the value of attribute away_points.
-
#clock ⇒ Object
Returns the value of attribute clock.
-
#description ⇒ Object
Returns the value of attribute description.
-
#down ⇒ Object
Returns the value of attribute down.
-
#end_situation ⇒ Object
Returns the value of attribute end_situation.
-
#event_type ⇒ Object
Returns the value of attribute event_type.
-
#home_points ⇒ Object
Returns the value of attribute home_points.
-
#id ⇒ Object
Returns the value of attribute id.
-
#play_clock ⇒ Object
Returns the value of attribute play_clock.
-
#play_type ⇒ Object
Returns the value of attribute play_type.
-
#player_data ⇒ Object
Returns the value of attribute player_data.
-
#player_id ⇒ Object
Returns the value of attribute player_id.
-
#players ⇒ Object
Returns the value of attribute players.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#response ⇒ Object
Returns the value of attribute response.
-
#score ⇒ Object
Returns the value of attribute score.
-
#scoring_play ⇒ Object
Returns the value of attribute scoring_play.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#start_situation ⇒ Object
Returns the value of attribute start_situation.
-
#statistics ⇒ Object
Returns the value of attribute statistics.
-
#team_id ⇒ Object
Returns the value of attribute team_id.
-
#type ⇒ Object
Returns the value of attribute type.
-
#wall_clock ⇒ Object
Returns the value of attribute wall_clock.
-
#yfd ⇒ Object
Returns the value of attribute yfd.
Instance Method Summary collapse
- #clock_seconds ⇒ Object
- #counted_play? ⇒ Boolean
- #deleted? ⇒ Boolean
- #down_distance ⇒ Object
- #end_of_regulation? ⇒ Boolean
- #end_spot ⇒ Object
- #halftime? ⇒ Boolean
-
#initialize(data, **opts) ⇒ Play
constructor
A new instance of Play.
- #parse_description_for_drive_end ⇒ Object
- #parse_player ⇒ Object
- #parsed_ending ⇒ Object
- #search_for_drive_end ⇒ Object
- #start_spot ⇒ Object
- #timeout? ⇒ Boolean
- #update(data, **opts) ⇒ Object
- #updated ⇒ 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) ⇒ Play
Returns a new instance of Play.
7 8 9 10 11 12 |
# File 'lib/sportradar/api/football/play.rb', line 7 def initialize(data, **opts) @response = data @id = data["id"] update(data, **opts) end |
Instance Attribute Details
#alt_description ⇒ Object
Returns the value of attribute alt_description.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def alt_description @alt_description end |
#away_points ⇒ Object
Returns the value of attribute away_points.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def away_points @away_points end |
#clock ⇒ Object
Returns the value of attribute clock.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def clock @clock end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def description @description end |
#down ⇒ Object
Returns the value of attribute down.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def down @down end |
#end_situation ⇒ Object
Returns the value of attribute end_situation.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def end_situation @end_situation end |
#event_type ⇒ Object
Returns the value of attribute event_type.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def event_type @event_type end |
#home_points ⇒ Object
Returns the value of attribute home_points.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def home_points @home_points end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def id @id end |
#play_clock ⇒ Object
Returns the value of attribute play_clock.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def play_clock @play_clock end |
#play_type ⇒ Object
Returns the value of attribute play_type.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def play_type @play_type end |
#player_data ⇒ Object
Returns the value of attribute player_data.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def player_data @player_data end |
#player_id ⇒ Object
Returns the value of attribute player_id.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def player_id @player_id end |
#players ⇒ Object
Returns the value of attribute players.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def players @players end |
#reference ⇒ Object
Returns the value of attribute reference.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def reference @reference end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def response @response end |
#score ⇒ Object
Returns the value of attribute score.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def score @score end |
#scoring_play ⇒ Object
Returns the value of attribute scoring_play.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def scoring_play @scoring_play end |
#sequence ⇒ Object
Returns the value of attribute sequence.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def sequence @sequence end |
#start_situation ⇒ Object
Returns the value of attribute start_situation.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def start_situation @start_situation end |
#statistics ⇒ Object
Returns the value of attribute statistics.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def statistics @statistics end |
#team_id ⇒ Object
Returns the value of attribute team_id.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def team_id @team_id end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def type @type end |
#wall_clock ⇒ Object
Returns the value of attribute wall_clock.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def wall_clock @wall_clock end |
#yfd ⇒ Object
Returns the value of attribute yfd.
5 6 7 |
# File 'lib/sportradar/api/football/play.rb', line 5 def yfd @yfd end |
Instance Method Details
#clock_seconds ⇒ Object
70 71 72 73 |
# File 'lib/sportradar/api/football/play.rb', line 70 def clock_seconds m,s = @clock.split(':') m.to_i * 60 + s.to_i end |
#counted_play? ⇒ Boolean
91 92 93 |
# File 'lib/sportradar/api/football/play.rb', line 91 def counted_play? ['rush', 'pass'].include?(self.play_type) && !self.description.include?('No Play') end |
#deleted? ⇒ Boolean
79 80 81 |
# File 'lib/sportradar/api/football/play.rb', line 79 def deleted? !!@deleted end |
#down_distance ⇒ Object
95 96 97 |
# File 'lib/sportradar/api/football/play.rb', line 95 def down_distance [down, yfd].compact.join(' & ') end |
#end_of_regulation? ⇒ Boolean
99 100 101 |
# File 'lib/sportradar/api/football/play.rb', line 99 def end_of_regulation? false end |
#end_spot ⇒ Object
87 88 89 |
# File 'lib/sportradar/api/football/play.rb', line 87 def end_spot end_situation&.spot end |
#halftime? ⇒ Boolean
107 108 109 |
# File 'lib/sportradar/api/football/play.rb', line 107 def halftime? @description == "End of 1st Half" end |
#parse_description_for_drive_end ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/sportradar/api/football/play.rb', line 138 def parse_description_for_drive_end parsed_ending = case @description when /no play/i nil when /intercepted/i :interception when /fumbles/i self.statistics&.fumble&.first&.lost? && :fumble when /extra point is good/i :touchdown # when missed extra point when /punts/i :punt when /Field Goal is No Good. blocked/i :fg when /Field Goal is No Good/i :fg # when missed field goal when /Field Goal is Good/i :fg when "End of 1st Half" :end_of_half else # end if parsed_ending parsed_ending end end |
#parse_player ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/sportradar/api/football/play.rb', line 168 def parse_player # TODO: Currently there is an issue where we are only mapping one player_id to a play, but there are plays with multiple players involved. play_stats = @statistics.penalty || @statistics.rush || @statistics.return || @statistics.receive if play_stats.is_a?(Array) play_stats = play_stats.first end @player_id = play_stats&.player&.id end |
#parsed_ending ⇒ Object
111 112 113 |
# File 'lib/sportradar/api/football/play.rb', line 111 def parsed_ending @parsed_ending ||= search_for_drive_end end |
#search_for_drive_end ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/sportradar/api/football/play.rb', line 115 def search_for_drive_end case @play_type when 'kick' nil when 'rush' # check for fumble parse_description_for_drive_end when 'pass' # check for fumble/interception parse_description_for_drive_end when 'punt' parse_description_for_drive_end when 'penalty' nil when 'fieldgoal' parse_description_for_drive_end # nullified plays still have FG when 'extrapoint' :pat else parse_description_for_drive_end end end |
#start_spot ⇒ Object
83 84 85 |
# File 'lib/sportradar/api/football/play.rb', line 83 def start_spot start_situation&.spot end |
#timeout? ⇒ Boolean
103 104 105 |
# File 'lib/sportradar/api/football/play.rb', line 103 def timeout? ['timeout', 'tvtimeout', 'teamtimeout'].include? @play_type end |
#update(data, **opts) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sportradar/api/football/play.rb', line 14 def update(data, **opts) @api = opts[:api] || @api @drive = opts[:drive] || @drive @description = data["description"] || data['summary'] || @description @alt_description = data['alt_description'] if data['alt_description'] @away_points = data['away_points'] if data['away_points'] @home_points = data['home_points'] if data['home_points'] @end_situation = Sportradar::Api::Football::Situation.new(data["end_situation"]) if data["end_situation"] @start_situation = Sportradar::Api::Football::Situation.new(data["start_situation"]) if data["start_situation"] @team_id = start_situation.team_id if start_situation @play_clock = data["play_clock"] @reference = data["reference"] @score = data["score"] @scoring_play = data["scoring_play"] @sequence = data["sequence"] @clock = data["clock"] if data["clock"] @type = data["type"] if data["type"] @summary = data["summary"] if data["summary"] @updated = Time.parse(data["updated"]) if data["updated"] @wall_clock = Time.parse(data["wall_clock"]) if data["wall_clock"] @side = data["side"] if data["side"] @yard_line = data["yard_line"] if data["yard_line"] @down = data["down"] if data["down"] @yfd = data["yfd"] if data["yfd"] @formation = data["formation"] if data["formation"] @direction = data["direction"] if data["direction"] @distance = data["distance"] if data["distance"] @participants = data["participants"] if data["participants"] @play_type = data["play_type"] || @play_type || data["event_type"] @sequence = data["sequence"] if data["sequence"] @event_type = data["event_type"] if data["event_type"] @deleted = data["deleted"] || @deleted @details = data["details"].gsub('.json', '') if data["details"] if data['statistics'] @statistics = Sportradar::Api::Football::PlayStatistics.new(data['statistics']) elsif data['players'] @player_data = data['players'] @statistics = Sportradar::Api::Football::PlayStatistics.new(data['players']) else @statistics ||= OpenStruct.new(players: []) end parse_player self end |
#updated ⇒ Object
66 67 68 |
# File 'lib/sportradar/api/football/play.rb', line 66 def updated @updated || @wall_clock end |