Class: Sportradar::Api::Football::Player

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

Direct Known Subclasses

Ncaafb::Player, Nfl::Player

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.



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

#apiObject

Returns the value of attribute api.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def api
  @api
end

#averagesObject

Returns the value of attribute averages.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def averages
  @averages
end

#birth_placeObject

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

#collegeObject

Returns the value of attribute college.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def college
  @college
end

#depthObject

Returns the value of attribute depth.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def depth
  @depth
end

#draftObject

Returns the value of attribute draft.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def draft
  @draft
end

#heightObject

Returns the value of attribute height.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def height
  @height
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def id
  @id
end

#name_firstObject

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_fullObject

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_lastObject

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

#numberObject

Returns the value of attribute number.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def number
  @number
end

#positionObject

Returns the value of attribute position.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def position
  @position
end

#preferred_nameObject

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

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def response
  @response
end

#statsObject

Returns the value of attribute stats.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def stats
  @stats
end

#totalsObject

Returns the value of attribute totals.



5
6
7
# File 'lib/sportradar/api/football/player.rb', line 5

def totals
  @totals
end

#weightObject

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

#ageObject



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_dateObject

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_nameObject



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_nameObject



17
18
19
# File 'lib/sportradar/api/football/player.rb', line 17

def first_name
  @name_first || @first_name
end

#injured?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/sportradar/api/football/player.rb', line 82

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

#jerseyObject



36
37
38
# File 'lib/sportradar/api/football/player.rb', line 36

def jersey
  @jersey_number
end

#last_nameObject



21
22
23
# File 'lib/sportradar/api/football/player.rb', line 21

def last_name
  @name_last || @last_name
end

#nameObject

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