Class: Basketball::Common::Player
- Defined in:
- lib/basketball/common/player.rb
Overview
Base class describing a player. A consumer application should extend these specific to their specific sports traits.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#overall ⇒ Object
readonly
Returns the value of attribute overall.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Attributes inherited from Entity
Instance Method Summary collapse
- #full_name ⇒ Object
-
#initialize(id:, overall: 0, position: nil, first_name: '', last_name: '') ⇒ Player
constructor
A new instance of Player.
- #to_s ⇒ Object
Methods inherited from Entity
#<=>, #==, #comparable_id, #hash
Constructor Details
#initialize(id:, overall: 0, position: nil, first_name: '', last_name: '') ⇒ Player
Returns a new instance of Player.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/basketball/common/player.rb', line 10 def initialize(id:, overall: 0, position: nil, first_name: '', last_name: '') super(id) raise ArgumentError, 'position is required' unless position @overall = overall @position = position @first_name = first_name @last_name = last_name freeze end |
Instance Attribute Details
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
8 9 10 |
# File 'lib/basketball/common/player.rb', line 8 def first_name @first_name end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
8 9 10 |
# File 'lib/basketball/common/player.rb', line 8 def last_name @last_name end |
#overall ⇒ Object (readonly)
Returns the value of attribute overall.
8 9 10 |
# File 'lib/basketball/common/player.rb', line 8 def overall @overall end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
8 9 10 |
# File 'lib/basketball/common/player.rb', line 8 def position @position end |
Instance Method Details
#full_name ⇒ Object
23 24 25 |
# File 'lib/basketball/common/player.rb', line 23 def full_name "#{first_name} #{last_name}".strip end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/basketball/common/player.rb', line 27 def to_s "[#{super}] #{full_name} (#{position}) #{overall}".strip end |