Class: Sportradar::Api::Baseball::Player
- Defined in:
- lib/sportradar/api/baseball/player.rb
Instance Attribute Summary collapse
-
#birth_place ⇒ Object
Returns the value of attribute birth_place.
-
#college ⇒ Object
Returns the value of attribute college.
-
#draft ⇒ Object
Returns the value of attribute draft.
-
#fielding ⇒ Object
Returns the value of attribute fielding.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#full_name ⇒ Object
Returns the value of attribute full_name.
-
#height ⇒ Object
Returns the value of attribute height.
-
#hitting ⇒ Object
Returns the value of attribute hitting.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#number ⇒ Object
Returns the value of attribute number.
-
#pitching ⇒ Object
Returns the value of attribute pitching.
-
#position ⇒ Object
Returns the value of attribute position.
-
#primary_position ⇒ Object
Returns the value of attribute primary_position.
-
#response ⇒ Object
Returns the value of attribute response.
-
#stats ⇒ Object
Returns the value of attribute stats.
-
#team ⇒ Object
Returns the value of attribute team.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #age ⇒ Object
- #api ⇒ Object
-
#birth_date ⇒ Object
to match api for NFL::Player.
- #display_name ⇒ Object
-
#initialize(data, **opts) ⇒ Player
constructor
A new instance of Player.
- #injured? ⇒ Boolean
- #jersey ⇒ Object
-
#name ⇒ Object
to match api for NFL::Player.
- #update(data, **opts) ⇒ Object
- #update_draft(data) ⇒ Object
- #update_injuries(data) ⇒ 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, **opts) ⇒ Player
Returns a new instance of Player.
7 8 9 10 11 12 13 14 15 |
# File 'lib/sportradar/api/baseball/player.rb', line 7 def initialize(data, **opts) @response = data # comment this out when done developing @api = opts[:api] @team = opts[:team] @id = data["id"] update(data, **opts) end |
Instance Attribute Details
#birth_place ⇒ Object
Returns the value of attribute birth_place.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def birth_place @birth_place end |
#college ⇒ Object
Returns the value of attribute college.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def college @college end |
#draft ⇒ Object
Returns the value of attribute draft.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def draft @draft end |
#fielding ⇒ Object
Returns the value of attribute fielding.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def fielding @fielding end |
#first_name ⇒ Object
Returns the value of attribute first_name.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def first_name @first_name end |
#full_name ⇒ Object
Returns the value of attribute full_name.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def full_name @full_name end |
#height ⇒ Object
Returns the value of attribute height.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def height @height end |
#hitting ⇒ Object
Returns the value of attribute hitting.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def hitting @hitting end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def id @id end |
#last_name ⇒ Object
Returns the value of attribute last_name.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def last_name @last_name end |
#number ⇒ Object
Returns the value of attribute number.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def number @number end |
#pitching ⇒ Object
Returns the value of attribute pitching.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def pitching @pitching end |
#position ⇒ Object
Returns the value of attribute position.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def position @position end |
#primary_position ⇒ Object
Returns the value of attribute primary_position.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def primary_position @primary_position end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def response @response end |
#stats ⇒ Object
Returns the value of attribute stats.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def stats @stats end |
#team ⇒ Object
Returns the value of attribute team.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def team @team end |
#weight ⇒ Object
Returns the value of attribute weight.
5 6 7 |
# File 'lib/sportradar/api/baseball/player.rb', line 5 def weight @weight end |
Instance Method Details
#age ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/sportradar/api/baseball/player.rb', line 81 def age if birth_date.present? now = Time.now.utc.to_date dob = birth_date.to_date now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1) end end |
#api ⇒ Object
103 104 105 |
# File 'lib/sportradar/api/baseball/player.rb', line 103 def api @api || Sportradar::Api::Baseball::Mlb::Api.new end |
#birth_date ⇒ Object
to match api for NFL::Player
27 28 29 |
# File 'lib/sportradar/api/baseball/player.rb', line 27 def birth_date # to match api for NFL::Player @birthdate end |
#display_name ⇒ Object
20 21 22 |
# File 'lib/sportradar/api/baseball/player.rb', line 20 def display_name full_name || "#{@preferred_name || @first_name} #{@last_name}" end |
#injured? ⇒ Boolean
77 78 79 |
# File 'lib/sportradar/api/baseball/player.rb', line 77 def injured? !!(@injury && @injury.out?) end |
#jersey ⇒ Object
23 24 25 |
# File 'lib/sportradar/api/baseball/player.rb', line 23 def jersey @jersey_number end |
#name ⇒ Object
to match api for NFL::Player
17 18 19 |
# File 'lib/sportradar/api/baseball/player.rb', line 17 def name # to match api for NFL::Player full_name end |
#update(data, **opts) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 |
# File 'lib/sportradar/api/baseball/player.rb', line 31 def update(data, **opts) @depth = data['depth'] if data['depth'] @experience = data['experience'] if data['experience'] @birth_place = data['birth_place'].gsub(',,', ', ') if data['birth_place'] @college = data['college'] if data['college'] # from team roster @status = data['status'] if data['status'] @position = data['position'] if data['position'] @primary_position = data['primary_position'] if data['primary_position'] @first_name = data['first_name'] if data['first_name'] @last_name = data['last_name'] if data['last_name'] @preferred_name = data['preferred_name'] if data['preferred_name'] @jersey_number = data['jersey_number'] if data['jersey_number'] @full_name = data['full_name'] if data['full_name'] @mlbam_id = data['mlbam_id'] if data['mlbam_id'] @height = data['height'] if data['height'] @weight = data['weight'] if data['weight'] @throw_hand = data['throw_hand'] if data['throw_hand'] @bat_hand = data['bat_hand'] if data['bat_hand'] @high_school = data['high_school'] if data['high_school'] @birthdate = data['birthdate'] if data['birthdate'] @birthstate = data['birthstate'] if data['birthstate'] @birthcountry = data['birthcountry'] if data['birthcountry'] @birthcity = data['birthcity'] if data['birthcity'] @pro_debut = data['pro_debut'] if data['pro_debut'] @updated = data['updated'] if data['updated'] @active = data['active'] if data['active'] update_injuries(data) update_draft(data) @team.update_player_stats(self, data['statistics'], opts[:game]) if data['statistics'] if @stats = data['statistics'] @fielding = @stats.dig('fielding', 'overall') @pitching = @stats.dig('pitching', 'overall') @hitting = @stats.dig('hitting', 'overall') # used to be @team, lets leave as opt until it needs to go back opts[:team].update_player_stats(self, @stats) end self end |
#update_draft(data) ⇒ Object
89 90 91 |
# File 'lib/sportradar/api/baseball/player.rb', line 89 def update_draft(data) @draft = data['draft'] if data['draft'] # {"team_id"=>"583ec825-fb46-11e1-82cb-f4ce4684ea4c", "year"=>"2012", "round"=>"1", "pick"=>"30"}, end |
#update_injuries(data) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/sportradar/api/baseball/player.rb', line 92 def update_injuries(data) # @injury = Injury.new(data['injuries']) if data['injuries'] # {"injury"=> # {"id"=>"06423591-3fc1-4d2b-8c60-a3f30d735345", # "comment"=>"Ezeli suffered a setback in his recovery from a procedure on his knee and there is no timetable for his return, according to Jason Quick of csnnw.com.", # "desc"=>"Knee", # "status"=>"Out", # "start_date"=>"2016-10-25", # "update_date"=>"2016-11-09"}}} end |