Class: ToyRobot::Roboto
- Inherits:
-
Object
- Object
- ToyRobot::Roboto
- Extended by:
- Forwardable
- Defined in:
- lib/toy_robot/roboto.rb,
lib/toy_robot/roboto/brain.rb,
lib/toy_robot/roboto/speech.rb,
lib/toy_robot/roboto/motor_cortex.rb
Defined Under Namespace
Classes: Brain, MotorCortex, Speech
Instance Attribute Summary collapse
-
#brain ⇒ Object
Returns the value of attribute brain.
-
#name ⇒ Object
Returns the value of attribute name.
-
#table_edges ⇒ Object
Returns the value of attribute table_edges.
Instance Method Summary collapse
-
#execute_order(order) ⇒ Object
Sends order’s method.
-
#initialize ⇒ Roboto
constructor
A new instance of Roboto.
-
#left ⇒ Object
Rotates roboto 90 degrees to the left if roboto is placed otherwise says advise message.
-
#move ⇒ Object
Moves roboto one unit forward to facing direction if roboto is placed and it’s safe otherwise says advise message.
-
#place(x:, y:, f:) ⇒ Object
Changes roboto location if is safe otherwise says advise message.
-
#placed? ⇒ Boolean
Returns true if location is nil.
-
#report ⇒ Object
Says current location if roboto is placed otherwise says advise message.
-
#right ⇒ Object
Rotates roboto 90 degrees to the right if roboto is placed otherwise says advise message.
Constructor Details
#initialize ⇒ Roboto
Returns a new instance of Roboto.
12 13 14 15 |
# File 'lib/toy_robot/roboto.rb', line 12 def initialize @brain = Brain.new @name = 'Roboto' end |
Instance Attribute Details
#brain ⇒ Object
Returns the value of attribute brain.
10 11 12 |
# File 'lib/toy_robot/roboto.rb', line 10 def brain @brain end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/toy_robot/roboto.rb', line 10 def name @name end |
#table_edges ⇒ Object
Returns the value of attribute table_edges.
10 11 12 |
# File 'lib/toy_robot/roboto.rb', line 10 def table_edges @table_edges end |
Instance Method Details
#execute_order(order) ⇒ Object
Sends order’s method
18 19 20 21 22 23 24 |
# File 'lib/toy_robot/roboto.rb', line 18 def execute_order(order) if order[:args].nil? send(order[:command]) else send(order[:command], order[:args]) end end |
#left ⇒ Object
Rotates roboto 90 degrees to the left if roboto is placed otherwise says advise message
56 57 58 59 60 |
# File 'lib/toy_robot/roboto.rb', line 56 def left if_placed do location.rotate_ccw end end |
#move ⇒ Object
Moves roboto one unit forward to facing direction if roboto is placed and it’s safe otherwise says advise message
37 38 39 40 41 42 43 44 |
# File 'lib/toy_robot/roboto.rb', line 37 def move if_placed do x, y = location.forward_prediction safe(x, y) do location.forward end end end |
#place(x:, y:, f:) ⇒ Object
Changes roboto location if is safe otherwise says advise message
28 29 30 31 32 |
# File 'lib/toy_robot/roboto.rb', line 28 def place(x:, y:, f:) safe(x, y) do location.reset(x: x.to_i, y: y.to_i, f: f.downcase.to_sym) end end |
#placed? ⇒ Boolean
Returns true if location is nil
71 72 73 |
# File 'lib/toy_robot/roboto.rb', line 71 def placed? !location.nil? end |
#report ⇒ Object
Says current location if roboto is placed otherwise says advise message
48 49 50 51 52 |
# File 'lib/toy_robot/roboto.rb', line 48 def report if_placed do puts speak(location.to_s) end end |
#right ⇒ Object
Rotates roboto 90 degrees to the right if roboto is placed otherwise says advise message
64 65 66 67 68 |
# File 'lib/toy_robot/roboto.rb', line 64 def right if_placed do location.rotate_cw end end |