another_toy_robot 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/toy_robot/command.rb +4 -4
- data/lib/toy_robot/direction.rb +28 -44
- data/lib/toy_robot/position.rb +3 -3
- data/lib/toy_robot/version.rb +1 -1
- data/toy_robot.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1399909208387cd5e03c5a6f89aa61623879d178
|
4
|
+
data.tar.gz: 974d0f67de3463964cbd82cffb1e0180b0db7a0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c79ac33ccca492a640630470d447ea98458c20ca1e939b185fa6d4502a849cd53f50f420dcaa224dabef1d93f8b991ba426b2789a6b67d9fbd4252e95206d922
|
7
|
+
data.tar.gz: 7c789bed5f724ff5609751fb9dbb72c439a354addbb92c7be9f8b2afc182b82213e611523fc944567627682211c44549746f59207b6060b38757622fe61b6cdf
|
data/lib/toy_robot/command.rb
CHANGED
@@ -22,10 +22,10 @@ class PlaceCommand
|
|
22
22
|
|
23
23
|
def direction
|
24
24
|
case @params[2]
|
25
|
-
when "n", "north" then North
|
26
|
-
when "e", "east" then East
|
27
|
-
when "s", "south" then South
|
28
|
-
when "w", "west" then West
|
25
|
+
when "n", "north" then North
|
26
|
+
when "e", "east" then East
|
27
|
+
when "s", "south" then South
|
28
|
+
when "w", "west" then West
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/lib/toy_robot/direction.rb
CHANGED
@@ -1,67 +1,51 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module North
|
2
|
+
X_DISPLACEMENT = 0
|
3
|
+
Y_DISPLACEMENT = 1
|
3
4
|
|
4
|
-
def
|
5
|
-
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
class North < Direction
|
10
|
-
def initialize
|
11
|
-
@x_displacement = 0
|
12
|
-
@y_displacement = 1
|
13
|
-
end
|
14
|
-
|
15
|
-
def left
|
16
|
-
West.new
|
5
|
+
def self.left
|
6
|
+
West
|
17
7
|
end
|
18
8
|
|
19
|
-
def right
|
20
|
-
East
|
9
|
+
def self.right
|
10
|
+
East
|
21
11
|
end
|
22
12
|
end
|
23
13
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@y_displacement = 0
|
28
|
-
end
|
14
|
+
module East
|
15
|
+
X_DISPLACEMENT = 1
|
16
|
+
Y_DISPLACEMENT = 0
|
29
17
|
|
30
|
-
def left
|
31
|
-
North
|
18
|
+
def self.left
|
19
|
+
North
|
32
20
|
end
|
33
21
|
|
34
|
-
def right
|
35
|
-
South
|
22
|
+
def self.right
|
23
|
+
South
|
36
24
|
end
|
37
25
|
end
|
38
26
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@y_displacement = -1
|
43
|
-
end
|
27
|
+
module South
|
28
|
+
X_DISPLACEMENT = 0
|
29
|
+
Y_DISPLACEMENT = -1
|
44
30
|
|
45
|
-
def left
|
46
|
-
East
|
31
|
+
def self.left
|
32
|
+
East
|
47
33
|
end
|
48
34
|
|
49
|
-
def right
|
50
|
-
West
|
35
|
+
def self.right
|
36
|
+
West
|
51
37
|
end
|
52
38
|
end
|
53
39
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
@y_displacement = 0
|
58
|
-
end
|
40
|
+
module West
|
41
|
+
X_DISPLACEMENT = -1
|
42
|
+
Y_DISPLACEMENT = 0
|
59
43
|
|
60
|
-
def left
|
61
|
-
South
|
44
|
+
def self.left
|
45
|
+
South
|
62
46
|
end
|
63
47
|
|
64
|
-
def right
|
65
|
-
North
|
48
|
+
def self.right
|
49
|
+
North
|
66
50
|
end
|
67
51
|
end
|
data/lib/toy_robot/position.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
class Position
|
2
2
|
attr_reader :x_coord, :y_coord, :direction
|
3
3
|
|
4
|
-
def initialize(x_coord: 0, y_coord: 0, direction: North
|
4
|
+
def initialize(x_coord: 0, y_coord: 0, direction: North)
|
5
5
|
@x_coord = x_coord
|
6
6
|
@y_coord = y_coord
|
7
7
|
@direction = direction
|
8
8
|
end
|
9
9
|
|
10
10
|
def advance
|
11
|
-
Position.new(x_coord: @x_coord + @direction
|
12
|
-
y_coord: @y_coord + @direction
|
11
|
+
Position.new(x_coord: @x_coord + @direction::X_DISPLACEMENT,
|
12
|
+
y_coord: @y_coord + @direction::Y_DISPLACEMENT,
|
13
13
|
direction: @direction)
|
14
14
|
end
|
15
15
|
|
data/lib/toy_robot/version.rb
CHANGED
data/toy_robot.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'toy_robot/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "another_toy_robot"
|
8
8
|
spec.version = ToyRobot::VERSION
|
9
|
-
spec.date = "2016-
|
9
|
+
spec.date = "2016-12-01"
|
10
10
|
spec.authors = "Sheldon J. Johnson"
|
11
11
|
spec.email = "sheldon.j.johnson@outlook.com"
|
12
12
|
spec.homepage = "https://github.com/drzel/toy_robot"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: another_toy_robot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sheldon J. Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "The application is a simulation of a toy robot moving on a square tabletop.\nIt
|
14
14
|
is an example of a well tested, object oriented design, employing the \ncommand
|