Class: Sportradar::Api::Soccer::Player
- Defined in:
- lib/sportradar/api/soccer/player.rb
Instance Attribute Summary collapse
-
#country_code ⇒ Object
readonly
Returns the value of attribute country_code.
-
#date_of_birth ⇒ Object
readonly
Returns the value of attribute date_of_birth.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#jersey_number ⇒ Object
readonly
Returns the value of attribute jersey_number.
-
#league_group ⇒ Object
readonly
Returns the value of attribute league_group.
-
#matches_played ⇒ Object
readonly
Returns the value of attribute matches_played.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nationality ⇒ Object
readonly
Returns the value of attribute nationality.
-
#preferred_foot ⇒ Object
readonly
Returns the value of attribute preferred_foot.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
-
#type ⇒ Object
(also: #position)
readonly
Returns the value of attribute type.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
- #api ⇒ Object
- #display_name ⇒ Object
- #first_name ⇒ Object
- #get_profile ⇒ Object
- #ingest_profile(data) ⇒ Object
-
#initialize(data = {}, league_group: nil, **opts) ⇒ Player
constructor
A new instance of Player.
- #last_name ⇒ Object
- #path_base ⇒ Object
- #path_profile ⇒ Object
- #queue_profile ⇒ Object
- #update(data, **opts) ⇒ 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 = {}, 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_code ⇒ Object (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_birth ⇒ Object (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 |
#height ⇒ Object (readonly)
Returns the value of attribute height.
6 7 8 |
# File 'lib/sportradar/api/soccer/player.rb', line 6 def height @height end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/sportradar/api/soccer/player.rb', line 6 def id @id end |
#jersey_number ⇒ Object (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_group ⇒ Object (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_played ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/sportradar/api/soccer/player.rb', line 6 def name @name end |
#nationality ⇒ Object (readonly)
Returns the value of attribute nationality.
6 7 8 |
# File 'lib/sportradar/api/soccer/player.rb', line 6 def nationality @nationality end |
#preferred_foot ⇒ Object (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 |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
6 7 8 |
# File 'lib/sportradar/api/soccer/player.rb', line 6 def stats @stats end |
#type ⇒ Object (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 |
#weight ⇒ Object (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
#api ⇒ Object
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_name ⇒ Object
49 50 51 |
# File 'lib/sportradar/api/soccer/player.rb', line 49 def display_name @name || [@first_name, @last_name].join(' ') end |
#first_name ⇒ Object
53 54 55 |
# File 'lib/sportradar/api/soccer/player.rb', line 53 def first_name @name.split()[1] end |
#get_profile ⇒ Object
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_name ⇒ Object
57 58 59 |
# File 'lib/sportradar/api/soccer/player.rb', line 57 def last_name @name.split()[0].delete(',') end |
#path_base ⇒ Object
65 66 67 |
# File 'lib/sportradar/api/soccer/player.rb', line 65 def path_base "players/#{ id }" end |
#path_profile ⇒ Object
69 70 71 |
# File 'lib/sportradar/api/soccer/player.rb', line 69 def path_profile "#{ path_base }/profile" end |
#queue_profile ⇒ Object
80 81 82 83 |
# File 'lib/sportradar/api/soccer/player.rb', line 80 def queue_profile url, headers, , timeout = api.get_request_info(path_profile) {url: url, headers: headers, params: , 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 |