Class: TwistyPuzzles::AbstractDirection
- Inherits:
-
Object
- Object
- TwistyPuzzles::AbstractDirection
show all
- Includes:
- Comparable
- Defined in:
- lib/twisty_puzzles/abstract_direction.rb
Overview
Base class for directions.
Constant Summary
collapse
- POSSIBLE_DIRECTION_NAMES =
[[''], ['2', '2\''], ['\'', '3', '’', '‘', '´', '`']].freeze
- SIMPLE_DIRECTION_NAMES =
(['0'] + POSSIBLE_DIRECTION_NAMES.map(&:first)).freeze
- POSSIBLE_SKEWB_DIRECTION_NAMES =
[['', '2\''], ['\'', '2']].freeze
- SIMPLE_SKEWB_DIRECTION_NAMES =
(['0'] + POSSIBLE_SKEWB_DIRECTION_NAMES.map(&:first)).freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of AbstractDirection.
12
13
14
15
16
17
18
19
|
# File 'lib/twisty_puzzles/abstract_direction.rb', line 12
def initialize(value)
raise TypeError, "Direction value #{value} isn't an integer." unless value.is_a?(Integer)
unless value >= 0 && value < self.class::NUM_DIRECTIONS
raise ArgumentError, "Invalid direction value #{value}."
end
@value = value
end
|
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
21
22
23
|
# File 'lib/twisty_puzzles/abstract_direction.rb', line 21
def value
@value
end
|
Instance Method Details
#+(other) ⇒ Object
39
40
41
|
# File 'lib/twisty_puzzles/abstract_direction.rb', line 39
def +(other)
self.class.new((@value + other.value) % self.class::NUM_DIRECTIONS)
end
|
#<=>(other) ⇒ Object
23
24
25
|
# File 'lib/twisty_puzzles/abstract_direction.rb', line 23
def <=>(other)
@value <=> other.value
end
|
#eql?(other) ⇒ Boolean
Also known as:
==
43
44
45
|
# File 'lib/twisty_puzzles/abstract_direction.rb', line 43
def eql?(other)
self.class.equal?(other.class) && @value == other.value
end
|
#hash ⇒ Object
49
50
51
|
# File 'lib/twisty_puzzles/abstract_direction.rb', line 49
def hash
@value.hash
end
|
#inverse ⇒ Object
35
36
37
|
# File 'lib/twisty_puzzles/abstract_direction.rb', line 35
def inverse
self.class.new((self.class::NUM_DIRECTIONS - @value) % self.class::NUM_DIRECTIONS)
end
|
#non_zero? ⇒ Boolean
31
32
33
|
# File 'lib/twisty_puzzles/abstract_direction.rb', line 31
def non_zero?
@value.positive?
end
|
#zero? ⇒ Boolean
27
28
29
|
# File 'lib/twisty_puzzles/abstract_direction.rb', line 27
def zero?
@value.zero?
end
|