Class: Direction
- Inherits:
-
TypesafeEnum::Base
- Object
- TypesafeEnum::Base
- Direction
- Defined in:
- lib/software_challenge_client/direction.rb
Overview
Access them as Direction::RIGHT for example.
Class Method Summary collapse
-
.from_to(from_direction, to_direction) ⇒ Turn
The Turn action to get from from_direction to to_direction.
-
.get_turn_direction(direction, turns) ⇒ Direction
The direction when turning the given number of steps from the given direction.
Class Method Details
.from_to(from_direction, to_direction) ⇒ Turn
Returns The Turn action to get from from_direction to to_direction.
31 32 33 34 35 36 37 |
# File 'lib/software_challenge_client/direction.rb', line 31 def self.from_to(from_direction, to_direction) distance = (to_direction.ord - from_direction.ord + 6) % 6 if distance > 3 distance = distance - 6 end Turn.new(distance) end |
.get_turn_direction(direction, turns) ⇒ Direction
Returns The direction when turning the given number of steps from the given direction.
25 26 27 28 |
# File 'lib/software_challenge_client/direction.rb', line 25 def self.get_turn_direction(direction, turns) # order of directions is equal to counterclockwise turning Direction.find_by_ord((direction.ord + turns) % 6) end |