lib/sportradar/api/soccer/player.rb in sportradar-api-0.1.12 vs lib/sportradar/api/soccer/player.rb in sportradar-api-0.1.13

- old
+ new

@@ -1,10 +1,10 @@ module Sportradar module Api class Soccer::Player < Data - attr_accessor :id, :first_name, :last_name, :country_code, :country, :reference_id, :full_first_name, :full_last_name, :position, :started, :jersey_number, :tactical_position, :tactical_order, :statistics, :preferred_foot, :birthdate, :height_in, :weight_lb, :height_cm, :weight_kg, :teams, :response, :rank, :total, :statistics, :last_modified + attr_accessor :id, :first_name, :last_name, :country_code, :country, :reference_id, :full_first_name, :full_last_name, :position, :started, :jersey_number, :tactical_position, :tactical_order, :statistics, :preferred_foot, :birthdate, :height_in, :weight_lb, :height_cm, :weight_kg, :teams, :response, :rank, :total, :statistics, :last_modified, :age def initialize(data) @response = data @id = data["id"] @first_name = data["first_name"] @@ -26,10 +26,11 @@ @birthdate = data["birthdate"] @height_in = data["height_in"] @weight_lb = data["weight_lb"] @height_cm = data["height_cm"] @weight_kg = data["weight_kg"] + @age = age set_teams @rank = data["rank"] @total = OpenStruct.new data["total"] if data["total"] @@ -51,9 +52,15 @@ end def tactical_position_name tactical_positions = { "0" => "Unknown", "1" => "Goalkeeper", "2" => "Right back", "3" => "Central defender", "4" => "Left back", "5" => "Right winger", "6" => "Central midfielder", "7" => "Left winger", "8" => "Forward" } tactical_positions[tactical_position] if tactical_position + end + + def age + now = Time.now.utc.to_date + dob = @birthdate.to_date + now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1) end private def set_teams