lib/sportradar/api/football/player.rb in sportradar-api-0.11.0 vs lib/sportradar/api/football/player.rb in sportradar-api-0.11.1

- old
+ new

@@ -1,10 +1,10 @@ module Sportradar module Api module Football class Player < Data - attr_accessor :response, :id, :number, :name_full, :name_first, :name_last, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft, :api + attr_accessor :response, :id, :preferred_name, :number, :name_full, :name_first, :name_last, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft, :api def initialize(data, **opts) @response = data @api = opts[:api] @team = opts[:team] @@ -12,15 +12,23 @@ @id = data["id"] update(data, **opts) end + def first_name + @name_first || @first_name + end + + def last_name + @name_last || @last_name + end + def name # to match api for NFL::Player name_full end def display_name - name_full + preferred_name ? "#{preferred_name} #{last_name}" : name_full end def birth_date # to match api for NFL::Player @birthdate end @@ -29,13 +37,14 @@ @jersey_number end def update(data, **opts) @status = data['status'] if data['status'] - @name_full = data['name_full'] || data['name'] || @name_full - @name_first = data['name_first'] if data['name_first'] - @name_last = data['name_last'] if data['name_last'] - @name_abbr = data['name_abbr'] if data['name_abbr'] + @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 \ No newline at end of file