Class: Robotoy::Robot

Inherits:
Object
  • Object
show all
Defined in:
lib/robotoy/robot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orients: [:north, :east, :south, :west]) ⇒ Robot

Returns a new instance of Robot.



5
6
7
# File 'lib/robotoy/robot.rb', line 5

def initialize(orients: [:north, :east, :south, :west])
  @orients = orients
end

Instance Attribute Details

#orientationObject

Returns the value of attribute orientation.



3
4
5
# File 'lib/robotoy/robot.rb', line 3

def orientation
  @orientation
end

#orientsObject

Returns the value of attribute orients.



3
4
5
# File 'lib/robotoy/robot.rb', line 3

def orients
  @orients
end

#xObject

Returns the value of attribute x.



3
4
5
# File 'lib/robotoy/robot.rb', line 3

def x
  @x
end

#yObject

Returns the value of attribute y.



3
4
5
# File 'lib/robotoy/robot.rb', line 3

def y
  @y
end

Instance Method Details

#validate_if_placedObject

Raises:



9
10
11
# File 'lib/robotoy/robot.rb', line 9

def validate_if_placed
  raise NotPlacedError if @x.nil? || @y.nil?
end

#validate_orientation(orientation:) ⇒ Object



13
14
15
# File 'lib/robotoy/robot.rb', line 13

def validate_orientation(orientation:)
  raise NotValidOrientationError unless @orients.include?(orientation.downcase)
end