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

#game_statsObject (readonly)

Returns the value of attribute game_stats.



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

def game_stats
  @game_stats
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



115
116
117
# File 'lib/sportradar/api/soccer/player.rb', line 115

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

#birth_dateObject



99
100
101
# File 'lib/sportradar/api/soccer/player.rb', line 99

def birth_date
  @date_of_birth
end

#display_nameObject



95
96
97
# File 'lib/sportradar/api/soccer/player.rb', line 95

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

#first_nameObject



107
108
109
# File 'lib/sportradar/api/soccer/player.rb', line 107

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

#get_profileObject



126
127
128
129
# File 'lib/sportradar/api/soccer/player.rb', line 126

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

#ingest_profile(data) ⇒ Object



130
131
132
133
# File 'lib/sportradar/api/soccer/player.rb', line 130

def ingest_profile(data)
  update(data)
  data
end

#jerseyObject



103
104
105
# File 'lib/sportradar/api/soccer/player.rb', line 103

def jersey
  @jersey_number
end

#last_nameObject



111
112
113
# File 'lib/sportradar/api/soccer/player.rb', line 111

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

#path_baseObject



119
120
121
# File 'lib/sportradar/api/soccer/player.rb', line 119

def path_base
  "players/#{ id }"
end

#path_profileObject



123
124
125
# File 'lib/sportradar/api/soccer/player.rb', line 123

def path_profile
  "#{ path_base }/profile"
end

#queue_profileObject



134
135
136
137
# File 'lib/sportradar/api/soccer/player.rb', line 134

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

#set_game_stats(data) ⇒ Object



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
84
85
86
87
88
89
90
91
92
93
# File 'lib/sportradar/api/soccer/player.rb', line 50

def set_game_stats(data)
  @game_stats ||= {}

  @game_stats[:substituted_in] = data['substituted_in'] if data['substituted_in'].present?
  @game_stats[:substituted_out] = data['substituted_out'] if data['substituted_out'].present?
  @game_stats[:goals_scored] = data['goals_scored'] if data['goals_scored'].present?
  @game_stats[:assists] = data['assists'] if data['assists'].present?
  @game_stats[:own_goals] = data['own_goals'] if data['own_goals'].present?
  @game_stats[:yellow_cards] = data['yellow_cards'] if data['yellow_cards'].present?
  @game_stats[:yellow_red_cards] = data['yellow_red_cards'] if data['yellow_red_cards'].present?
  @game_stats[:red_cards] = data['red_cards'] if data['red_cards'].present?
  @game_stats[:goal_line_clearances] = data['goal_line_clearances'] if data['goal_line_clearances'].present?
  @game_stats[:interceptions] = data['interceptions'] if data['interceptions'].present?
  @game_stats[:chances_created] = data['chances_created'] if data['chances_created'].present?
  @game_stats[:crosses_successful] = data['crosses_successful'] if data['crosses_successful'].present?
  @game_stats[:crosses_total] = data['crosses_total'] if data['crosses_total'].present?
  @game_stats[:passes_short_successful] = data['passes_short_successful'] if data['passes_short_successful'].present?
  @game_stats[:passes_medium_successful] = data['passes_medium_successful'] if data['passes_medium_successful'].present?
  @game_stats[:passes_long_successful] = data['passes_long_successful'] if data['passes_long_successful'].present?
  @game_stats[:passes_short_total] = data['passes_short_total'] if data['passes_short_total'].present?
  @game_stats[:passes_medium_total] = data['passes_medium_total'] if data['passes_medium_total'].present?
  @game_stats[:passes_long_total] = data['passes_long_total'] if data['passes_long_total'].present?
  @game_stats[:duels_header_successful] = data['duels_header_successful'] if data['duels_header_successful'].present?
  @game_stats[:duels_sprint_successful] = data['duels_sprint_successful'] if data['duels_sprint_successful'].present?
  @game_stats[:duels_tackle_successful] = data['duels_tackle_successful'] if data['duels_tackle_successful'].present?
  @game_stats[:duels_header_total] = data['duels_header_total'] if data['duels_header_total'].present?
  @game_stats[:duels_sprint_total] = data['duels_sprint_total'] if data['duels_sprint_total'].present?
  @game_stats[:duels_tackle_total] = data['duels_tackle_total'] if data['duels_tackle_total'].present?
  @game_stats[:goals_conceded] = data['goals_conceded'] if data['goals_conceded'].present?
  @game_stats[:shots_faced_saved] = data['shots_faced_saved'] if data['shots_faced_saved'].present?
  @game_stats[:shots_faced_total] = data['shots_faced_total'] if data['shots_faced_total'].present?
  @game_stats[:penalties_faced] = data['penalties_faced'] if data['penalties_faced'].present?
  @game_stats[:penalties_saved] = data['penalties_saved'] if data['penalties_saved'].present?
  @game_stats[:fouls_committed] = data['fouls_committed'] if data['fouls_committed'].present?
  @game_stats[:was_fouled] = data['was_fouled'] if data['was_fouled'].present?
  @game_stats[:offsides] = data['offsides'] if data['offsides'].present?
  @game_stats[:shots_on_goal] = data['shots_on_goal'] if data['shots_on_goal'].present?
  @game_stats[:shots_off_goal] = data['shots_off_goal'] if data['shots_off_goal'].present?
  @game_stats[:shots_blocked] = data['shots_blocked'] if data['shots_blocked'].present?
  @game_stats[:minutes_played] = data['minutes_played'] if data['minutes_played'].present?
  @game_stats[:performance_score] = data['performance_score'] if data['performance_score'].present?
  @game_stats[:goals_by_head] = data['goals_by_head'] if data['goals_by_head'].present?
  @game_stats[:goals_by_penalty] = data['goals_by_penalty'] if data['goals_by_penalty'].present?
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
48
# 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']
  set_game_stats(data)

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

end