toy_robot_cli 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9ea2b0b48996a8fcb4f68df38f7773060e92ac1221d36e09eb05268a6cb6db6
4
- data.tar.gz: '0145910220ff22a216dfe8b4ffe4786d337a993d0a8b743c52b9092fa716b7b9'
3
+ metadata.gz: 5a3133755b582dabf6ef44af7158ab89e3fbf6c92a765e579ebd2e38b736b7d7
4
+ data.tar.gz: a6c15e28cd2c552f4e5a5fe37cbdb2e903311fac82676c8c6de7960dcb2f0c52
5
5
  SHA512:
6
- metadata.gz: be4037d0629acfd481136ea6ab35a7875a3b3ec2670a55d9e93e86f866b0b1c555b98366a5e0518c288431803f4ac64d5183479ff6cb7d19da149cf9eb7c1133
7
- data.tar.gz: aa39acda6ad7fb7b128970fc40420888a314c784c83bb81f2a951a3a48a7d7bcbe439d439a3769e9a49ee83508848111b8029fce45cfaf24ecf8016d42cdec12
6
+ metadata.gz: ca4c27c5b823f86f59d96ea39d60d88409d70165108671dd543c88e86f4570fee619420735456dde3f4d21b11490ffebb7472423443482d03ec46a7c6369efea
7
+ data.tar.gz: fbd92d9c66ef0ab748296773933f55947e0535b585c67d77d1c475ab8369a67999c04de2c9e8ca1b266d610f0cdb0cf5948d2b17a9c1e25a321765281cb20acb
data/README.md CHANGED
@@ -33,6 +33,8 @@ The available commands are:
33
33
  - left: Rotate the robot 90 degrees to the left.
34
34
  - right: Rotate the robot 90 degrees to the right.
35
35
  - report: Report the current position and direction of the robot.
36
+ - current_position: Report the current position of the robot.
37
+ - current_direction: Report the current direction of the robot is facing.
36
38
 
37
39
  Here's an example usage:
38
40
 
@@ -44,6 +46,8 @@ $ toy_robot
44
46
  > right
45
47
  > move
46
48
  > report
49
+ > current_position
50
+ > current_direction
47
51
  ```
48
52
 
49
53
  ## Development
@@ -36,6 +36,16 @@ module ToyRobotCli
36
36
  puts @robot.report
37
37
  end
38
38
 
39
+ desc "current_position", "Return the current position of the robot"
40
+ def current_position
41
+ position = @robot.current_position
42
+ if position
43
+ puts "Current Position: #{position[0]}, #{position[1]}"
44
+ else
45
+ puts "Robot is not placed on the table."
46
+ end
47
+ end
48
+
39
49
  desc "interactive", "Interactive mode to input commands"
40
50
  def interactive
41
51
  loop do
@@ -55,6 +65,8 @@ module ToyRobotCli
55
65
  right
56
66
  when "report"
57
67
  report
68
+ when "current_position"
69
+ current_position
58
70
  when "exit"
59
71
  break
60
72
  else
@@ -32,6 +32,40 @@ module ToyRobotCli
32
32
  @direction = VALID_DIRECTIONS.index(facing)
33
33
  end
34
34
 
35
+ # Get the current position (X, Y) of the robot.
36
+ # Example:
37
+ # >> robot = ToyRobotCli::Robot.new
38
+ # => #<ToyRobotCli::Robot:0x000000... @direction=nil, @position=nil>
39
+ # >> robot.place(0, 0, "SOUTH")
40
+ # => 2
41
+ # >> robot.current_position
42
+ # => [2, 2]
43
+ #
44
+ # Returns:
45
+ # (Array) - An array containing the X and Y coordinates of the robot's current position.
46
+ def current_position
47
+ return nil unless placed?
48
+
49
+ @position.to_a.flatten
50
+ end
51
+
52
+ # Get the current direction of the robot.
53
+ # Example:
54
+ # >> robot = ToyRobotCli::Robot.new
55
+ # => #<ToyRobotCli::Robot:0x000000... @direction=nil, @position=nil>
56
+ # >> robot.place(0, 0, "SOUTH")
57
+ # => 2
58
+ # >> robot.current_direction
59
+ # => "SOUTH"
60
+ #
61
+ # Returns:
62
+ # (String) - An array containing the X and Y coordinates of the robot's current position.
63
+ def current_direction
64
+ return nil unless placed?
65
+
66
+ VALID_DIRECTIONS[@direction]
67
+ end
68
+
35
69
  # Move the robot one unit forward in the current direction.
36
70
  def move
37
71
  return unless placed?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ToyRobotCli
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toy_robot_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo H Sacramento
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-18 00:00:00.000000000 Z
11
+ date: 2023-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba