Class: MarsRover::Rover

Inherits:
Object
  • Object
show all
Defined in:
lib/mars_rover/rover.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, direction, plateau) ⇒ Rover

Returns a new instance of Rover.

Raises:



12
13
14
15
16
17
18
19
# File 'lib/mars_rover/rover.rb', line 12

def initialize(x, y, direction, plateau)
  self.x = x
  self.y = y
  self.direction = direction
  self.plateau = plateau

  raise RoverError unless valid_position?
end

Instance Attribute Details

#directionObject

Returns the value of attribute direction.



10
11
12
# File 'lib/mars_rover/rover.rb', line 10

def direction
  @direction
end

#plateauObject

Returns the value of attribute plateau.



10
11
12
# File 'lib/mars_rover/rover.rb', line 10

def plateau
  @plateau
end

#xObject

Returns the value of attribute x.



10
11
12
# File 'lib/mars_rover/rover.rb', line 10

def x
  @x
end

#yObject

Returns the value of attribute y.



10
11
12
# File 'lib/mars_rover/rover.rb', line 10

def y
  @y
end

Instance Method Details

#moveObject



29
30
31
# File 'lib/mars_rover/rover.rb', line 29

def move
  MarsRover::Position.move(self)
end

#run_command(command) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/mars_rover/rover.rb', line 33

def run_command(command)
  case command
  when 'L'
    turn_left
  when 'R'
    turn_right
  when 'M'
    move
  end
end

#turn_leftObject



25
26
27
# File 'lib/mars_rover/rover.rb', line 25

def turn_left
  MarsRover::Direction.turn_left(self)
end

#turn_rightObject



21
22
23
# File 'lib/mars_rover/rover.rb', line 21

def turn_right
  MarsRover::Direction.turn_right(self)
end