Class: Robotoy::Robot
- Inherits:
-
Object
- Object
- Robotoy::Robot
- Defined in:
- lib/robotoy/robot.rb
Instance Attribute Summary collapse
-
#orientation ⇒ Object
Returns the value of attribute orientation.
-
#orients ⇒ Object
Returns the value of attribute orients.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(orients: [:north, :east, :south, :west]) ⇒ Robot
constructor
A new instance of Robot.
- #validate_if_placed ⇒ Object
- #validate_orientation(orientation:) ⇒ Object
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
#orientation ⇒ Object
Returns the value of attribute orientation.
3 4 5 |
# File 'lib/robotoy/robot.rb', line 3 def orientation @orientation end |
#orients ⇒ Object
Returns the value of attribute orients.
3 4 5 |
# File 'lib/robotoy/robot.rb', line 3 def orients @orients end |
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/robotoy/robot.rb', line 3 def x @x end |
#y ⇒ Object
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_placed ⇒ Object
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 |