Class: ToyRobotCli::CLI
- Inherits:
-
Thor
- Object
- Thor
- ToyRobotCli::CLI
- Defined in:
- lib/toy_robot_cli/cli.rb
Constant Summary collapse
- VALID_DIRECTIONS =
%w[NORTH EAST SOUTH WEST].freeze
Instance Method Summary collapse
- #current_direction ⇒ Object
- #current_position ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #interactive ⇒ Object
- #left ⇒ Object
- #move ⇒ Object
- #place(x, y, facing) ⇒ Object
- #report ⇒ Object
- #right ⇒ Object
Constructor Details
Instance Method Details
#current_direction ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/toy_robot_cli/cli.rb', line 50 def current_direction direction = @robot.current_direction if direction puts "Current Direction: #{direction}" else puts "Robot is not placed on the table." end end |
#current_position ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/toy_robot_cli/cli.rb', line 40 def current_position position = @robot.current_position if position puts "Current Position: #{position[0]}, #{position[1]}" else puts "Robot is not placed on the table." end end |
#interactive ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/toy_robot_cli/cli.rb', line 60 def interactive loop do print "> " input = $stdin.gets.chomp.downcase command, *args = input.split(" ") case command when "place" place(*args) when "move" move when "left" left when "right" right when "report" report when "current_position" current_position when "current_direction" current_direction when "exit" break else puts "Invalid command. Please try again." end end end |
#left ⇒ Object
25 26 27 |
# File 'lib/toy_robot_cli/cli.rb', line 25 def left @robot.left end |
#move ⇒ Object
20 21 22 |
# File 'lib/toy_robot_cli/cli.rb', line 20 def move @robot.move end |
#place(x, y, facing) ⇒ Object
15 16 17 |
# File 'lib/toy_robot_cli/cli.rb', line 15 def place(x, y, facing) @robot.place(x.to_i, y.to_i, facing.upcase) end |
#report ⇒ Object
35 36 37 |
# File 'lib/toy_robot_cli/cli.rb', line 35 def report puts @robot.report end |
#right ⇒ Object
30 31 32 |
# File 'lib/toy_robot_cli/cli.rb', line 30 def right @robot.right end |