class NHLStats::Player
Attributes
active[R]
birth_date[R]
first_name[R]
full_name[R]
id[R]
last_name[R]
nationality[R]
number[R]
position[R]
Public Class Methods
find(id)
click to toggle source
# File lib/nhl_stats/player.rb, line 20 def self.find(id) response = Faraday.get("#{API_ROOT}/people/#{id}") attributes = JSON.parse(response.body).dig("people", 0) new(attributes) end
new(player_data)
click to toggle source
# File lib/nhl_stats/player.rb, line 6 def initialize(player_data) @id = player_data["id"] @full_name = player_data["fullName"] @number = (player_data["primaryNumber"] || player_data["jerseyNumber"]).to_i @position = player_data.dig("primaryPosition", "abbreviation") || player_data.dig("position", "abbreviation") # Roster response returns an array of players w/o the following if player_data.key?("firstName") roster_response_data(player_data) else @active = true end end
Private Instance Methods
roster_response_data(player_data)
click to toggle source
# File lib/nhl_stats/player.rb, line 28 def roster_response_data(player_data) @first_name = player_data["firstName"] @last_name = player_data["lastName"] @birth_date = Date.parse(player_data["birthDate"]) @nationality = player_data["nationality"] @active = player_data["active"] end