Class: Sportradar::Api::Soccer::Player

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/soccer/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 = {}, league_group: nil, **opts) ⇒ Player

Returns a new instance of Player.



9
10
11
12
13
14
15
16
17
18
# File 'lib/sportradar/api/soccer/player.rb', line 9

def initialize(data = {}, league_group: nil, **opts)
  @response     = data
  @id           = data['id'] if data['id']
  @api          = opts[:api]
  @team         = opts[:team]

  @league_group = league_group || data['league_group'] || @api&.league_group

  update(data, **opts)
end

Instance Attribute Details

#country_codeObject (readonly)

Returns the value of attribute country_code.



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

def country_code
  @country_code
end

#date_of_birthObject (readonly)

Returns the value of attribute date_of_birth.



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

def date_of_birth
  @date_of_birth
end

#heightObject (readonly)

Returns the value of attribute height.



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

def height
  @height
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#jersey_numberObject (readonly)

Returns the value of attribute jersey_number.



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

def jersey_number
  @jersey_number
end

#league_groupObject (readonly)

Returns the value of attribute league_group.



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

def league_group
  @league_group
end

#matches_playedObject (readonly)

Returns the value of attribute matches_played.



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

def matches_played
  @matches_played
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#nationalityObject (readonly)

Returns the value of attribute nationality.



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

def nationality
  @nationality
end

#preferred_footObject (readonly)

Returns the value of attribute preferred_foot.



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

def preferred_foot
  @preferred_foot
end

#statsObject (readonly)

Returns the value of attribute stats.



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

def stats
  @stats
end

#typeObject (readonly) Also known as: position

Returns the value of attribute type.



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

def type
  @type
end

#weightObject (readonly)

Returns the value of attribute weight.



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

def weight
  @weight
end

Instance Method Details

#apiObject



61
62
63
# File 'lib/sportradar/api/soccer/player.rb', line 61

def api
  @api || Sportradar::Api::Soccer::Api.new(league_group: @league_group)
end

#display_nameObject



49
50
51
# File 'lib/sportradar/api/soccer/player.rb', line 49

def display_name
  @name || [@first_name, @last_name].join(' ')
end

#first_nameObject



53
54
55
# File 'lib/sportradar/api/soccer/player.rb', line 53

def first_name
  @name.split()[1]
end

#get_profileObject



72
73
74
75
# File 'lib/sportradar/api/soccer/player.rb', line 72

def get_profile
  data = api.get_data(path_profile).to_h
  ingest_profile(data)
end

#ingest_profile(data) ⇒ Object



76
77
78
79
# File 'lib/sportradar/api/soccer/player.rb', line 76

def ingest_profile(data)
  update(data)
  data
end

#last_nameObject



57
58
59
# File 'lib/sportradar/api/soccer/player.rb', line 57

def last_name
  @name.split()[0].delete(',')
end

#path_baseObject



65
66
67
# File 'lib/sportradar/api/soccer/player.rb', line 65

def path_base
  "players/#{ id }"
end

#path_profileObject



69
70
71
# File 'lib/sportradar/api/soccer/player.rb', line 69

def path_profile
  "#{ path_base }/profile"
end

#queue_profileObject



80
81
82
83
# File 'lib/sportradar/api/soccer/player.rb', line 80

def queue_profile
  url, headers, options, timeout = api.get_request_info(path_profile)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_profile)}
end

#update(data, **opts) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sportradar/api/soccer/player.rb', line 20

def update(data, **opts)
  @id             = data['id']             if data['id']
  @league_group = opts[:league_group] || data['league_group'] || @league_group

  if data['player']
    update(data['player'])
  end

  @name           = data['name']           if data['name']
  @last_name      = data['last_name']      if data['last_name']
  @first_name     = data['first_name']     if data['first_name']
  @type           = data['type']           if data['type']
  @nationality    = data['nationality']    if data['nationality']
  @country_code   = data['country_code']   if data['country_code']
  @height         = data['height']         if data['height']
  @weight         = data['weight']         if data['weight']
  @jersey_number  = data['jersey_number']  if data['jersey_number']
  @preferred_foot = data['preferred_foot'] if data['preferred_foot']
  @matches_played = data['matches_played'] if data['matches_played']
  @stats          = data['statistics']     if data['statistics']
  @date_of_birth  = Date.parse(data['date_of_birth']) if data['date_of_birth']

  @team.update_player_stats(self, data['statistics']) if data['statistics'] && @team
  if opts[:match]
    @team.update_player_stats(self, data, opts[:match])
  end

end