Class: Sportradar::Api::Football::PlayStatistics
- Defined in:
- lib/sportradar/api/football/play_statistics.rb
Instance Attribute Summary collapse
-
#defense ⇒ Object
Returns the value of attribute defense.
-
#down_conversion ⇒ Object
Returns the value of attribute down_conversion.
-
#extra_point ⇒ Object
Returns the value of attribute extra_point.
-
#field_goal ⇒ Object
Returns the value of attribute field_goal.
-
#first_down ⇒ Object
Returns the value of attribute first_down.
-
#fumble ⇒ Object
Returns the value of attribute fumble.
-
#kick ⇒ Object
Returns the value of attribute kick.
-
#pass ⇒ Object
Returns the value of attribute pass.
-
#penalty ⇒ Object
Returns the value of attribute penalty.
-
#punt ⇒ Object
Returns the value of attribute punt.
-
#receive ⇒ Object
Returns the value of attribute receive.
-
#response ⇒ Object
Returns the value of attribute response.
-
#return ⇒ Object
Returns the value of attribute return.
-
#rush ⇒ Object
Returns the value of attribute rush.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ PlayStatistics
constructor
A new instance of PlayStatistics.
- #players ⇒ Object
- #players_by_team ⇒ 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) ⇒ PlayStatistics
Returns a new instance of PlayStatistics.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 6 def initialize(data) data = [data] if data.is_a?(Hash) @response = data if data.first['name'] # indicates college data structures. we want to convert it to nfl data structures data = data.flat_map do |hash| types = self.class.college_type_translations.each_key.select { |str| hash.key?(str) } types.map do |type| stats = hash.delete(type) new_team = { 'id' => hash['team'], 'alias' => hash['team'] } # use intermediate variable to avoid temp memory blowup { 'player' => hash, 'team' => new_team, 'stat_type' => self.class.college_type_translations[type] }.merge(stats) end end end data.each do |hash| var = instance_variable_get("@#{hash['stat_type']}") unless var instance_variable_set("@#{hash['stat_type']}", []) var = instance_variable_get("@#{hash['stat_type']}") end klass = self.class.stat_type_classes[hash['stat_type']] || MiscStatistics var << klass.new(hash) end end |
Instance Attribute Details
#defense ⇒ Object
Returns the value of attribute defense.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def defense @defense end |
#down_conversion ⇒ Object
Returns the value of attribute down_conversion.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def down_conversion @down_conversion end |
#extra_point ⇒ Object
Returns the value of attribute extra_point.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def extra_point @extra_point end |
#field_goal ⇒ Object
Returns the value of attribute field_goal.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def field_goal @field_goal end |
#first_down ⇒ Object
Returns the value of attribute first_down.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def first_down @first_down end |
#fumble ⇒ Object
Returns the value of attribute fumble.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def fumble @fumble end |
#kick ⇒ Object
Returns the value of attribute kick.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def kick @kick end |
#pass ⇒ Object
Returns the value of attribute pass.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def pass @pass end |
#penalty ⇒ Object
Returns the value of attribute penalty.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def penalty @penalty end |
#punt ⇒ Object
Returns the value of attribute punt.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def punt @punt end |
#receive ⇒ Object
Returns the value of attribute receive.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def receive @receive end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def response @response end |
#return ⇒ Object
Returns the value of attribute return.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def return @return end |
#rush ⇒ Object
Returns the value of attribute rush.
5 6 7 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 5 def rush @rush end |
Class Method Details
.college_type_translations ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 40 def self.college_type_translations @college_type_translations ||= { "kickoffs" => 'kick', "kick_return" => 'return', "rushing" => 'rush', "fumble" => 'fumble', "defense" => 'defense', "receiving" => 'receive', "punting" => 'punt', "penalty" => 'penalty', "passing" => 'pass', "field_goal" => 'field_goal', "extra_point" => 'extra_point', "blocked_field_goal_return" => 'block', "interception_return" => 'return', "fumble_return" => 'return', "punt_return" => 'return', "two_point_conversion" => 'conversion', 'misc' => 'misc', }.freeze end |
.stat_type_classes ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 62 def self.stat_type_classes @stat_type_classes ||= { 'kick' => PlayKickStatistics, 'return' => PlayReturnStatistics, 'rush' => PlayRushStatistics, 'fumble' => PlayFumbleStatistics, 'defense' => PlayDefenseStatistics, 'receive' => PlayReceiveStatistics, 'punt' => PlayPuntStatistics, 'penalty' => PlayPenaltyStatistics, 'pass' => PlayPassingStatistics, 'first_down' => PlayFirstDownStatistics, 'field_goal' => PlayFieldGoalStatistics, 'extra_point' => PlayExtraPointStatistics, 'down_conversion' => PlayDownConversionStatistics, 'conversion' => ConversionStatistics, 'block' => BlockStatistics, 'misc' => MiscStatistics, }.freeze end |
Instance Method Details
#players ⇒ Object
30 31 32 33 34 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 30 def players @players ||= [:kick, :return, :rush, :defense, :receive, :punt, :penalty, :pass, :field_goal, :defense, :down_conversion].flat_map do |stat_type| Array(send(stat_type)).map { |stat| (stat.player.team = stat.team.id; stat.player) if stat.player }.compact # this is cause of kick returns w/ touchbacks end end |
#players_by_team ⇒ Object
36 37 38 |
# File 'lib/sportradar/api/football/play_statistics.rb', line 36 def players_by_team @players_by_team ||= players.group_by(&:team) end |