Class: Basketball::Common::Player

Inherits:
Entity
  • Object
show all
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

Draft::Player, Season::Player

Instance Attribute Summary collapse

Attributes inherited from Entity

#id

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


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_nameObject (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_nameObject (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

#overallObject (readonly)

Returns the value of attribute overall.



8
9
10
# File 'lib/basketball/common/player.rb', line 8

def overall
  @overall
end

#positionObject (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_nameObject



23
24
25
# File 'lib/basketball/common/player.rb', line 23

def full_name
  "#{first_name} #{last_name}".strip
end

#to_sObject



27
28
29
# File 'lib/basketball/common/player.rb', line 27

def to_s
  "[#{super}] #{full_name} (#{position}) #{overall}".strip
end