Class: Sportradar::Api::Basketball::Nba::Player

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/basketball/nba/player.rb

Instance Attribute 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) ⇒ 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

#averagesObject

Returns the value of attribute averages.



6
7
8
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6

def averages
  @averages
end

#birth_placeObject

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

#collegeObject

Returns the value of attribute college.



6
7
8
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6

def college
  @college
end

#draftObject

Returns the value of attribute draft.



6
7
8
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6

def draft
  @draft
end

#first_nameObject

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_nameObject

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

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6

def height
  @height
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6

def id
  @id
end

#last_nameObject

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

#numberObject

Returns the value of attribute number.



6
7
8
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6

def number
  @number
end

#positionObject

Returns the value of attribute position.



6
7
8
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6

def position
  @position
end

#responseObject

Returns the value of attribute response.



6
7
8
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6

def response
  @response
end

#statsObject

Returns the value of attribute stats.



6
7
8
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6

def stats
  @stats
end

#totalsObject

Returns the value of attribute totals.



6
7
8
# File 'lib/sportradar/api/basketball/nba/player.rb', line 6

def totals
  @totals
end

#weightObject

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

#ageObject



87
88
89
90
91
92
93
# File 'lib/sportradar/api/basketball/nba/player.rb', line 87

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

#apiObject



143
144
145
# File 'lib/sportradar/api/basketball/nba/player.rb', line 143

def api
  @api || Sportradar::Api::Basketball::Nba::Api.new
end

#birth_dateObject

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_nameObject



35
36
37
# File 'lib/sportradar/api/basketball/nba/player.rb', line 35

def display_name
  full_name
end

#injured?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/sportradar/api/basketball/nba/player.rb', line 83

def injured?
  !!(@injury && @injury.out?)
end

#jerseyObject



38
39
40
# File 'lib/sportradar/api/basketball/nba/player.rb', line 38

def jersey
  @jersey_number
end

#nameObject

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
# 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",

# 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



129
130
131
# File 'lib/sportradar/api/basketball/nba/player.rb', line 129

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



132
133
134
135
136
137
138
139
140
141
# File 'lib/sportradar/api/basketball/nba/player.rb', line 132

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