toy_robot_cli 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/toy_robot_cli/cli.rb +12 -0
- data/lib/toy_robot_cli/robot.rb +15 -0
- data/lib/toy_robot_cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b9465bbbfd49f2de70e762e66b8ebb85a42e058e047dc190d459c4cfa9e0674
|
4
|
+
data.tar.gz: c1d8c7b25605ba93871bae39756c0f0f9f86c263dd784f789b4156cc7a645283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f9bd0a617f9fc83256dfeae4ef9ef879f761f49b9a4c00642b322792beacaf50223cb02fdf48954bc46dbc7a8da2e729e6d107cfa23dc282a311a34e58a7cc3
|
7
|
+
data.tar.gz: 06367b0746873f1af22aa0b9e0a0bc9e103683d501f9183274307201e1c170ad0b4c97e6fb9f7f07007ad7e2d65d83e7c2fa9745a01fb90010f496cd61fda3a8
|
data/README.md
CHANGED
@@ -33,6 +33,7 @@ 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.
|
36
37
|
|
37
38
|
Here's an example usage:
|
38
39
|
|
@@ -44,6 +45,7 @@ $ toy_robot
|
|
44
45
|
> right
|
45
46
|
> move
|
46
47
|
> report
|
48
|
+
> current_position
|
47
49
|
```
|
48
50
|
|
49
51
|
## Development
|
data/lib/toy_robot_cli/cli.rb
CHANGED
@@ -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
|
data/lib/toy_robot_cli/robot.rb
CHANGED
@@ -32,6 +32,21 @@ 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
|
+
#
|
42
|
+
# Returns:
|
43
|
+
# (Array) - An array containing the X and Y coordinates of the robot's current position.
|
44
|
+
def current_position
|
45
|
+
return nil unless placed?
|
46
|
+
|
47
|
+
@position.to_a.flatten
|
48
|
+
end
|
49
|
+
|
35
50
|
# Move the robot one unit forward in the current direction.
|
36
51
|
def move
|
37
52
|
return unless placed?
|
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.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2023-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aruba
|