Class: Sportradar::Api::Basketball::Nba::Player
- Defined in:
- lib/sportradar/api/basketball/nba/player.rb
Instance Attribute Summary collapse
-
#averages ⇒ Object
Returns the value of attribute averages.
-
#birth_place ⇒ Object
Returns the value of attribute birth_place.
-
#college ⇒ Object
Returns the value of attribute college.
-
#draft ⇒ Object
Returns the value of attribute draft.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#full_name ⇒ Object
Returns the value of attribute full_name.
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#not_playing_description ⇒ Object
Returns the value of attribute not_playing_description.
-
#not_playing_reason ⇒ Object
Returns the value of attribute not_playing_reason.
-
#number ⇒ Object
Returns the value of attribute number.
-
#position ⇒ Object
Returns the value of attribute position.
-
#response ⇒ Object
Returns the value of attribute response.
-
#stats ⇒ Object
Returns the value of attribute stats.
-
#team ⇒ Object
Returns the value of attribute team.
-
#totals ⇒ Object
Returns the value of attribute totals.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #age ⇒ Object
- #api ⇒ Object
-
#birth_date ⇒ Object
to match api for NFL::Player.
- #display_name ⇒ Object
-
#initialize(data, **opts) ⇒ Player
constructor
A new instance of Player.
- #injured? ⇒ Boolean
- #jersey ⇒ Object
-
#name ⇒ Object
to match api for NFL::Player.
- #update(data, **opts) ⇒ Object
-
#update_draft(data) ⇒ Object
def stats { “played”=>“true”, “active”=>“true”, “starter”=>“true”, “statistics”=> “field_goals_made”=>“5”, “field_goals_att”=>“11”, “field_goals_pct”=>“45.5”, “three_points_made”=>“1”, “three_points_att”=>“5”, “three_points_pct”=>“20.0”, “two_points_made”=>“4”, “two_points_att”=>“6”, “two_points_pct”=>“66.667”, “blocked_att”=>“0”, “free_throws_made”=>“2”, “free_throws_att”=>“2”, “free_throws_pct”=>“100.0”, “offensive_rebounds”=>“1”, “defensive_rebounds”=>“3”, “rebounds”=>“4”, “assists”=>“6”, “turnovers”=>“2”, “steals”=>“0”, “blocks”=>“0”, “assists_turnover_ratio”=>“3.0”, “personal_fouls”=>“1”, “tech_fouls”=>“0”, “flagrant_fouls”=>“0”, “pls_min”=>“4”, “points”=>“13”} end.
- #update_injuries(data) ⇒ 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) ⇒ Player
Returns a new instance of Player.
22 23 24 25 26 27 28 29 30 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 22 def initialize(data, **opts) @response = data @api = opts[:api] @team = opts[:team] @id = data["id"] update(data, **opts) end |
Instance Attribute Details
#averages ⇒ Object
Returns the value of attribute averages.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def averages @averages end |
#birth_place ⇒ Object
Returns the value of attribute birth_place.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def birth_place @birth_place end |
#college ⇒ Object
Returns the value of attribute college.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def college @college end |
#draft ⇒ Object
Returns the value of attribute draft.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def draft @draft end |
#first_name ⇒ Object
Returns the value of attribute first_name.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def first_name @first_name end |
#full_name ⇒ Object
Returns the value of attribute full_name.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def full_name @full_name end |
#height ⇒ Object
Returns the value of attribute height.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def height @height end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def id @id end |
#last_name ⇒ Object
Returns the value of attribute last_name.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def last_name @last_name end |
#not_playing_description ⇒ Object
Returns the value of attribute not_playing_description.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def @not_playing_description end |
#not_playing_reason ⇒ Object
Returns the value of attribute not_playing_reason.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def @not_playing_reason end |
#number ⇒ Object
Returns the value of attribute number.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def number @number end |
#position ⇒ Object
Returns the value of attribute position.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def position @position end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def response @response end |
#stats ⇒ Object
Returns the value of attribute stats.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def stats @stats end |
#team ⇒ Object
Returns the value of attribute team.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def team @team end |
#totals ⇒ Object
Returns the value of attribute totals.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def totals @totals end |
#weight ⇒ Object
Returns the value of attribute weight.
6 7 8 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6 def weight @weight end |
Instance Method Details
#age ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 89 def age if birth_date now = Time.now.utc.to_date dob = Date.parse(birth_date) now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1) end end |
#api ⇒ Object
145 146 147 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 145 def api @api || Sportradar::Api::Basketball::Nba::Api.new end |
#birth_date ⇒ Object
to match api for NFL::Player
42 43 44 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 42 def birth_date # to match api for NFL::Player @birthdate end |
#display_name ⇒ Object
35 36 37 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 35 def display_name full_name end |
#injured? ⇒ Boolean
85 86 87 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 85 def injured? !!(@injury && @injury.out?) end |
#jersey ⇒ Object
38 39 40 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 38 def jersey @jersey_number end |
#name ⇒ Object
to match api for NFL::Player
32 33 34 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 32 def name # to match api for NFL::Player full_name end |
#update(data, **opts) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 46 def update(data, **opts) @status = data['status'] if data['status'] # "ACT", @full_name = data['full_name'] if data['full_name'] # "Festus Ezeli", @first_name = data['first_name'] if data['first_name'] # "Festus", @last_name = data['last_name'] if data['last_name'] # "Ezeli", @abbr_name = data['abbr_name'] if data['abbr_name'] # "F.Ezeli", @height = data['height'] if data['height'] # "83", @weight = data['weight'] if data['weight'] # "265", @position = data['position'] if data['position'] # "C", @primary_position = data['primary_position'] if data['primary_position'] # "C", @jersey_number = data['jersey_number'] if data['jersey_number'] # "31", @experience = data['experience'] if data['experience'] # "3", @birth_place = data['birth_place'].gsub(',,', ', ') if data['birth_place'] # "Benin City,, NGA", @updated = data['updated'] if data['updated'] # "2016-07-08T12:11:59+00:00", @not_playing_reason = data['not_playing_reason'] if data['not_playing_reason'] # "Inactive - Injury/Illness" @not_playing_description = data['not_playing_description'] if data['not_playing_description'] # "Left Ankle; Sprain" # NBA specific below @college = data['college'] if data['college'] # "Vanderbilt", @birthdate = data['birthdate'] if data['birthdate'] # "1989-10-21", update_injuries(data) update_draft(data) @team.update_player_stats(self, data['statistics'], opts[:game]) if data['statistics'] if avgs = data['average'] @totals = data['total'] @averages = avgs @stats = { 'total' => @totals, 'averages' => @averages, } @team.update_player_stats(self, avgs) end self end |
#update_draft(data) ⇒ Object
def stats
{
"played"=>"true",
"active"=>"true",
"starter"=>"true",
"statistics"=>
{"minutes"=>"33:23",
"field_goals_made"=>"5",
"field_goals_att"=>"11",
"field_goals_pct"=>"45.5",
"three_points_made"=>"1",
"three_points_att"=>"5",
"three_points_pct"=>"20.0",
"two_points_made"=>"4",
"two_points_att"=>"6",
"two_points_pct"=>"66.667",
"blocked_att"=>"0",
"free_throws_made"=>"2",
"free_throws_att"=>"2",
"free_throws_pct"=>"100.0",
"offensive_rebounds"=>"1",
"defensive_rebounds"=>"3",
"rebounds"=>"4",
"assists"=>"6",
"turnovers"=>"2",
"steals"=>"0",
"blocks"=>"0",
"assists_turnover_ratio"=>"3.0",
"personal_fouls"=>"1",
"tech_fouls"=>"0",
"flagrant_fouls"=>"0",
"pls_min"=>"4",
"points"=>"13"}}
end
131 132 133 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 131 def update_draft(data) @draft = data['draft'] if data['draft'] # {"team_id"=>"583ec825-fb46-11e1-82cb-f4ce4684ea4c", "year"=>"2012", "round"=>"1", "pick"=>"30"}, end |
#update_injuries(data) ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/sportradar/api/basketball/nba/player.rb', line 134 def update_injuries(data) @injury = Injury.new(data['injuries']) if data['injuries'] # {"injury"=> # {"id"=>"06423591-3fc1-4d2b-8c60-a3f30d735345", # "comment"=>"Ezeli suffered a setback in his recovery from a procedure on his knee and there is no timetable for his return, according to Jason Quick of csnnw.com.", # "desc"=>"Knee", # "status"=>"Out", # "start_date"=>"2016-10-25", # "update_date"=>"2016-11-09"}}} end |