Class: Basketball::Common::Position

Inherits:
ValueObject show all
Extended by:
Forwardable
Defined in:
lib/basketball/common/position.rb

Overview

Describes a player position.

Direct Known Subclasses

Draft::Position, Season::Position

Defined Under Namespace

Classes: InvalidPositionError

Constant Summary collapse

BACK_COURT_VALUES =
%w[PG SG SF].to_set.freeze
FRONT_COURT_VALUES =
%w[PF C].to_set.freeze
ALL_VALUES =
(BACK_COURT_VALUES.to_a + FRONT_COURT_VALUES.to_a).to_set.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ValueObject

#<=>, #==, #[], #all_sorted_values, #hash, #to_h, #to_s

Methods included from ValueObjectDSL

#all_sorted_value_keys, #all_value_keys, #value_keys, #value_reader

Constructor Details

#initialize(code) ⇒ Position

Returns a new instance of Position.



25
26
27
28
29
30
31
32
33
# File 'lib/basketball/common/position.rb', line 25

def initialize(code)
  super()

  @code = code.to_s.upcase

  raise InvalidPositionError, "Unknown position code: #{@code}" unless ALL_VALUES.include?(@code)

  freeze
end

Class Method Details

.randomObject



10
11
12
# File 'lib/basketball/common/position.rb', line 10

def random
  new(ALL_VALUES.to_a.sample)
end