Class: Sportradar::Api::Football::Player
- Defined in:
- lib/sportradar/api/football/player.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api ⇒ Object
Returns the value of attribute api.
-
#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.
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#draft ⇒ Object
Returns the value of attribute draft.
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name_first ⇒ Object
Returns the value of attribute name_first.
-
#name_full ⇒ Object
Returns the value of attribute name_full.
-
#name_last ⇒ Object
Returns the value of attribute name_last.
-
#number ⇒ Object
Returns the value of attribute number.
-
#position ⇒ Object
Returns the value of attribute position.
-
#preferred_name ⇒ Object
Returns the value of attribute preferred_name.
-
#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
-
#birth_date ⇒ Object
to match api for NFL::Player.
- #display_name ⇒ Object
- #first_name ⇒ Object
-
#initialize(data, **opts) ⇒ Player
constructor
A new instance of Player.
- #injured? ⇒ Boolean
- #jersey ⇒ Object
- #last_name ⇒ Object
-
#name ⇒ Object
to match api for NFL::Player.
- #update(data, **opts) ⇒ Object
- #update_draft(data) ⇒ Object
- #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.
7 8 9 10 11 12 13 14 15 |
# File 'lib/sportradar/api/football/player.rb', line 7 def initialize(data, **opts) @response = data @api = opts[:api] @team = opts[:team] @id = data["id"] update(data, **opts) end |
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def api @api end |
#averages ⇒ Object
Returns the value of attribute averages.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def averages @averages end |
#birth_place ⇒ Object
Returns the value of attribute birth_place.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def birth_place @birth_place end |
#college ⇒ Object
Returns the value of attribute college.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def college @college end |
#depth ⇒ Object
Returns the value of attribute depth.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def depth @depth end |
#draft ⇒ Object
Returns the value of attribute draft.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def draft @draft end |
#height ⇒ Object
Returns the value of attribute height.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def height @height end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def id @id end |
#name_first ⇒ Object
Returns the value of attribute name_first.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def name_first @name_first end |
#name_full ⇒ Object
Returns the value of attribute name_full.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def name_full @name_full end |
#name_last ⇒ Object
Returns the value of attribute name_last.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def name_last @name_last end |
#number ⇒ Object
Returns the value of attribute number.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def number @number end |
#position ⇒ Object
Returns the value of attribute position.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def position @position end |
#preferred_name ⇒ Object
Returns the value of attribute preferred_name.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def preferred_name @preferred_name end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def response @response end |
#stats ⇒ Object
Returns the value of attribute stats.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def stats @stats end |
#team ⇒ Object
Returns the value of attribute team.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def team @team end |
#totals ⇒ Object
Returns the value of attribute totals.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def totals @totals end |
#weight ⇒ Object
Returns the value of attribute weight.
5 6 7 |
# File 'lib/sportradar/api/football/player.rb', line 5 def weight @weight end |
Instance Method Details
#age ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/sportradar/api/football/player.rb', line 86 def age # if birth_date.present? # now = Time.now.utc.to_date # dob = birth_date.to_date # now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1) # end end |
#birth_date ⇒ Object
to match api for NFL::Player
32 33 34 |
# File 'lib/sportradar/api/football/player.rb', line 32 def birth_date # to match api for NFL::Player @birthdate end |
#display_name ⇒ Object
28 29 30 |
# File 'lib/sportradar/api/football/player.rb', line 28 def display_name preferred_name ? "#{preferred_name} #{last_name}" : name_full end |
#first_name ⇒ Object
17 18 19 |
# File 'lib/sportradar/api/football/player.rb', line 17 def first_name @name_first || @first_name end |
#injured? ⇒ Boolean
82 83 84 |
# File 'lib/sportradar/api/football/player.rb', line 82 def injured? # !!(@injury && @injury.out?) end |
#jersey ⇒ Object
36 37 38 |
# File 'lib/sportradar/api/football/player.rb', line 36 def jersey @jersey_number end |
#last_name ⇒ Object
21 22 23 |
# File 'lib/sportradar/api/football/player.rb', line 21 def last_name @name_last || @last_name end |
#name ⇒ Object
to match api for NFL::Player
25 26 27 |
# File 'lib/sportradar/api/football/player.rb', line 25 def name # to match api for NFL::Player name_full end |
#update(data, **opts) ⇒ Object
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sportradar/api/football/player.rb', line 40 def update(data, **opts) @status = data['status'] if data['status'] @preferred_name = data['preferred_name'] || data['name_preferred'] || @preferred_name @name_full = data['name_full'] || data['name'] || @name_full @name_first = data['name_first'] || data['first_name'] || @name_first @name_last = data['name_last'] || data['last_name'] || @name_last @name_abbr = data['name_abbr'] || data['abbr_name'] || @name_abbr @height = data['height'] if data['height'] @weight = data['weight'] if data['weight'] @position = data['position'] if data['position'] @primary_position = data['primary_position'] if data['primary_position'] @jersey_number = data['jersey_number'] || data['jersey'] || @jersey_number @experience = data['experience'] if data['experience'] @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", @depth = data['depth'] if data['depth'] @games_started = data['games_started'] if data['games_started'] @games_played = data['games_played'] if data['games_played'] # NCAA specific below # update_injuries(data) # update_draft(data) if @stats = data['statistics'] @totals = @stats # binding.pry @team.update_player_stats(self, @stats.dup, opts[:game]) elsif @stats = data['games_played'] @stats = data.dup %w[id name jersey reference position].each do |useless_key| @stats.delete(useless_key) end @totals = @stats else @totals = {} end self end |
#update_draft(data) ⇒ Object
94 95 96 |
# File 'lib/sportradar/api/football/player.rb', line 94 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
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sportradar/api/football/player.rb', line 97 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 |