Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- lib/dmorrill10-utils/integer.rb
Overview
Table game specific ##########
Instance Method Summary collapse
-
#position_relative_to(seat, number_of_players) ⇒ Integer
The relative position of
self
toseat
, given the number of players at the table,number_of_players
, indexed such that the seat immediately to the left ofseat
has aposition_relative_to
of zero. -
#seat_from_relative_position(relative_position_of_self_to_result, number_of_players) ⇒ Integer
Inverse operation of
position_relative_to
. -
#seat_in_bounds?(number_of_players) ⇒ Bool
Reports whether or not
self
represents an out of bounds seat.
Instance Method Details
#position_relative_to(seat, number_of_players) ⇒ Integer
Returns The relative position of self
to seat
, given the number of players at the table, number_of_players
, indexed such that the seat immediately to the left of seat
has a position_relative_to
of zero.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dmorrill10-utils/integer.rb', line 17 def position_relative_to(seat, number_of_players) raise SeatOutOfBounds unless seat.seat_in_bounds?(number_of_players) && seat_in_bounds?(number_of_players) adjusted_seat = if self > seat self else self + number_of_players end adjusted_seat - seat - 1 end |
#seat_from_relative_position(relative_position_of_self_to_result, number_of_players) ⇒ Integer
Inverse operation of position_relative_to
. Given
<code>relative_position = seat.position_relative_to to_seat, number_of_players</code>
then
<code>to_seat = seat.seat_from_relative_position relative_position, number_of_players</code>
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dmorrill10-utils/integer.rb', line 45 def seat_from_relative_position(relative_position_of_self_to_result, number_of_players) raise SeatOutOfBounds unless seat_in_bounds?(number_of_players) unless relative_position_of_self_to_result.seat_in_bounds?(number_of_players) raise RelativePositionOutOfBounds end position_adjustment = relative_position_of_self_to_result + 1 to_seat = self + number_of_players - position_adjustment if self > to_seat || !to_seat.seat_in_bounds?(number_of_players) self - position_adjustment else to_seat end end |
#seat_in_bounds?(number_of_players) ⇒ Bool
Returns Reports whether or not self
represents an out of bounds seat.
66 67 68 |
# File 'lib/dmorrill10-utils/integer.rb', line 66 def seat_in_bounds?(number_of_players) self < number_of_players && self >= 0 end |