Sha256: f83dd4c1d2b925912c14a576a4ca7cff02840604c4438e60499648fb4c889d33
Contents?: true
Size: 866 Bytes
Versions: 2
Compression:
Stored size: 866 Bytes
Contents
# frozen_string_literal: true module Basketball module Drafting class Position extend Forwardable class << self def random new(ALL_VALUES.to_a.sample) end end class InvalidPositionError < StandardError; end 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 attr_reader :value def_delegators :value, :to_s def initialize(value) @value = value.to_s.upcase raise InvalidPositionError, "Unknown position value: #{@value}" unless ALL_VALUES.include?(@value) freeze end def ==(other) value == other.value end alias eql? == def hash value.hash end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
basketball-0.0.2 | lib/basketball/drafting/position.rb |
basketball-0.0.1 | lib/basketball/drafting/position.rb |