Class: NHLStats::Player
- Inherits:
-
Object
- Object
- NHLStats::Player
- Defined in:
- lib/nhl_stats/player.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#birth_date ⇒ Object
readonly
Returns the value of attribute birth_date.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#nationality ⇒ Object
readonly
Returns the value of attribute nationality.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(player_data) ⇒ Player
constructor
A new instance of Player.
Constructor Details
#initialize(player_data) ⇒ Player
Returns a new instance of Player.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
3 4 5 |
# File 'lib/nhl_stats/player.rb', line 3 def active @active end |
#birth_date ⇒ Object (readonly)
Returns the value of attribute birth_date.
3 4 5 |
# File 'lib/nhl_stats/player.rb', line 3 def birth_date @birth_date end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
3 4 5 |
# File 'lib/nhl_stats/player.rb', line 3 def first_name @first_name end |
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
3 4 5 |
# File 'lib/nhl_stats/player.rb', line 3 def full_name @full_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/nhl_stats/player.rb', line 3 def id @id end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
3 4 5 |
# File 'lib/nhl_stats/player.rb', line 3 def last_name @last_name end |
#nationality ⇒ Object (readonly)
Returns the value of attribute nationality.
3 4 5 |
# File 'lib/nhl_stats/player.rb', line 3 def nationality @nationality end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
3 4 5 |
# File 'lib/nhl_stats/player.rb', line 3 def number @number end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
3 4 5 |
# File 'lib/nhl_stats/player.rb', line 3 def position @position end |
Class Method Details
.find(id) ⇒ Object
20 21 22 23 24 |
# 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 |