another_toy_robot 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +16 -19
- data/{toy_robot.gemspec → another_toy_robot.gemspec} +4 -4
- data/bin/another_toy_robot +4 -0
- data/bin/console +1 -1
- data/lib/{toy_robot.rb → another_toy_robot.rb} +3 -3
- data/lib/{toy_robot → another_toy_robot}/arena.rb +0 -0
- data/lib/{toy_robot → another_toy_robot}/client.rb +2 -2
- data/lib/{toy_robot → another_toy_robot}/command.rb +0 -0
- data/lib/{toy_robot → another_toy_robot}/direction.rb +0 -0
- data/lib/{toy_robot → another_toy_robot}/input.rb +6 -6
- data/lib/{toy_robot → another_toy_robot}/invalid_command.rb +1 -1
- data/lib/{toy_robot → another_toy_robot}/left_command.rb +1 -1
- data/lib/{toy_robot → another_toy_robot}/move_command.rb +1 -1
- data/lib/{toy_robot → another_toy_robot}/null_position.rb +0 -0
- data/lib/{toy_robot → another_toy_robot}/place_command.rb +1 -1
- data/lib/{toy_robot → another_toy_robot}/position.rb +1 -1
- data/lib/{toy_robot → another_toy_robot}/report_command.rb +1 -1
- data/lib/{toy_robot → another_toy_robot}/right_command.rb +1 -1
- data/lib/{toy_robot → another_toy_robot}/robot.rb +3 -3
- data/lib/another_toy_robot/version.rb +3 -0
- metadata +21 -21
- data/bin/toy_robot +0 -4
- data/lib/toy_robot/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbbb001b13b2aece8fbc3472fde61dbd182f15a2
|
4
|
+
data.tar.gz: f082074f51a05499991610fa313020112bd53cf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3aca4553c6b12365fc69f971d998570d020a314df936462cfac410db436498b84d0817426bead5838029731b6799a5057597353856d7d03ae6e2f603764ed87
|
7
|
+
data.tar.gz: 2be5502641219c8bd3a7d102a154ca06043cded28d02aebae3cf0fc3ec699dc35572f55fdbf39abde4fa3a25b0d86bbd75def000f3769cf2645c84dc8f82c5b0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/another_toy_robot.svg)](https://badge.fury.io/rb/another_toy_robot)
|
2
|
-
[![Code Climate](https://codeclimate.com/github/drzel/
|
3
|
-
[![Test Coverage](https://codeclimate.com/github/drzel/
|
4
|
-
[![Build Status](https://travis-ci.org/drzel/
|
2
|
+
[![Code Climate](https://codeclimate.com/github/drzel/another_toy_robot/badges/gpa.svg)](https://codeclimate.com/github/drzel/another_toy_robot)
|
3
|
+
[![Test Coverage](https://codeclimate.com/github/drzel/another_toy_robot/badges/coverage.svg)](https://codeclimate.com/github/drzel/another_toy_robot/coverage)
|
4
|
+
[![Build Status](https://travis-ci.org/drzel/another_toy_robot.svg?branch=master)](https://travis-ci.org/drzel/another_toy_robot)
|
5
5
|
|
6
6
|
# Another Toy Robot Simulator
|
7
7
|
The application is a simulation of a toy robot moving on a 5 x 5 unit tabletop. It is an example of a well tested, object oriented design, employing the command design pattern. It is commonly used as an code-test. See specifications below for the full text of the test.
|
@@ -24,8 +24,8 @@ $ gem install another_toy_robot
|
|
24
24
|
|
25
25
|
Alternatively it can be built from source:
|
26
26
|
```
|
27
|
-
$ git clone https://github.com/drzel/
|
28
|
-
$ cd
|
27
|
+
$ git clone https://github.com/drzel/another_toy_robot.git
|
28
|
+
$ cd another_toy_robot
|
29
29
|
$ bundle install
|
30
30
|
```
|
31
31
|
|
@@ -39,7 +39,7 @@ Unit tests are written to [Sandi Metz' Unit Testing Minimalist](https://youtu.be
|
|
39
39
|
|
40
40
|
### Usage
|
41
41
|
```
|
42
|
-
$
|
42
|
+
$ another_toy_robot
|
43
43
|
```
|
44
44
|
|
45
45
|
This will present a prompt:
|
@@ -66,32 +66,29 @@ The app implements:
|
|
66
66
|
- The [null-object pattern](https://en.wikipedia.org/wiki/Null_Object_pattern) (for positions)
|
67
67
|
- The [singleton pattern](https://en.wikipedia.org/wiki/Singleton_pattern) (for directions)
|
68
68
|
|
69
|
-
`
|
69
|
+
`another_toy_robot` is an executable in your load path. It is a Ruby script that calls the main function:
|
70
70
|
```
|
71
71
|
#!/usr/bin/env ruby
|
72
72
|
|
73
|
-
require "
|
74
|
-
|
73
|
+
require "another_toy_robot"
|
74
|
+
AnotherToyRobot.main
|
75
75
|
```
|
76
76
|
|
77
|
-
`
|
77
|
+
`AnotherToyRobot#main` instantiates a new `Client`. The `Client` instantiates an `Arena` and `Robot` objects. The new `Robot` is initialised with `NullPosition` in the `Arena`.
|
78
|
+
|
79
|
+
The main loop does the following:
|
78
80
|
|
79
|
-
- The main loop does the following:
|
80
81
|
- Requests user input
|
81
82
|
- Instantiates a new `Input` object
|
82
|
-
- Passes the new `Input` object to the client
|
83
|
+
- Passes the new `Input` object to the client's `#command_for` method
|
83
84
|
|
84
85
|
The `Input` class contains methods to parse the user input and determine the correct `Command` class for the given command. E.g. `"move"` will resolve a the `MoveCommand` while `"derp"` will resolve `InvalidCommand`.
|
85
86
|
|
86
|
-
The
|
87
|
+
The `Client#command_for` method calls the `Input#new_command` method, passing the `@robot` as the target.
|
87
88
|
|
88
89
|
The `xCommand` object will parse any arguments provided and call the appropriate action on the `@robot`.
|
89
90
|
|
90
|
-
When receiving
|
91
|
-
|
92
|
-
When receiving `#left`, `#right` or `#move`, the robot will pass the request to its `@position` which will respond with the new position.
|
93
|
-
|
94
|
-
The `Robot` will then check with its `@arena` to see if the position is `#inbounds` before assigning the new position to itself.
|
91
|
+
When receiving `#left`, `#right` or `#move`, the robot will pass the request to its `@position` which will respond with the new position. The `#place` method obtains it's position from the commands parameters. Then `Robot` will then check with its `@arena` to see if the position is `#inbounds` before assigning the new position to itself.
|
95
92
|
|
96
93
|
When receiving a `#left`, `#right` or `#move` message the `NullPosition` will return itself.
|
97
94
|
|
@@ -102,7 +99,7 @@ This process continues until an `"exit"` command is received, breaking the loop.
|
|
102
99
|
### Considerations
|
103
100
|
Given the requirement for a command line interface to interact with the robot, I settled on the well established and widely used command pattern.
|
104
101
|
|
105
|
-
The `Input` wrapper allows new commands to be easily added. E.g. Creating a new file `lib/
|
102
|
+
The `Input` wrapper allows new commands to be easily added. E.g. Creating a new file `lib/another_toy_robot/random_command.rb` and requiring it, would be all that is required for the application to accept the `"random"` command, and it would have access to an array of parameters. Validations can also be added by defining a `valid?` method on the command object. See the `lib/another_toy_robot/place_command.rb` for an example.
|
106
103
|
|
107
104
|
I'm particularly happy with the `Position` class and the `Direction` modules. Together as a unit they have absolutely no dependencies and could be easily reused with new features, new objects, or with changing specifications. It would be reasonably straight forward to add a second robot, or a third dimension.
|
108
105
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "
|
4
|
+
require "another_toy_robot/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "another_toy_robot"
|
8
|
-
spec.version =
|
8
|
+
spec.version = AnotherToyRobot::VERSION
|
9
9
|
spec.date = "2016-12-05"
|
10
10
|
spec.authors = "Sheldon J. Johnson"
|
11
11
|
spec.email = "sheldon.j.johnson@outlook.com"
|
12
|
-
spec.homepage = "https://github.com/drzel/
|
12
|
+
spec.homepage = "https://github.com/drzel/another_toy_robot"
|
13
13
|
spec.summary = "Another toy robot demonstration app"
|
14
14
|
spec.required_ruby_version = ">= 2.3"
|
15
15
|
spec.license = "MIT"
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
end
|
24
24
|
|
25
25
|
spec.bindir = "bin"
|
26
|
-
spec.executables << "
|
26
|
+
spec.executables << "another_toy_robot"
|
27
27
|
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.5"
|
29
29
|
spec.add_development_dependency "rake", "~> 11.3"
|
data/bin/console
CHANGED
File without changes
|
File without changes
|
File without changes
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require "
|
2
|
-
require "
|
3
|
-
require "
|
4
|
-
require "
|
5
|
-
require "
|
6
|
-
require "
|
1
|
+
require "another_toy_robot/move_command"
|
2
|
+
require "another_toy_robot/left_command"
|
3
|
+
require "another_toy_robot/right_command"
|
4
|
+
require "another_toy_robot/place_command"
|
5
|
+
require "another_toy_robot/report_command"
|
6
|
+
require "another_toy_robot/invalid_command"
|
7
7
|
|
8
8
|
class Input
|
9
9
|
def initialize(input)
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sheldon J. Johnson
|
@@ -85,7 +85,7 @@ description: The application is a simulation of a toy robot moving on a square t
|
|
85
85
|
pattern.
|
86
86
|
email: sheldon.j.johnson@outlook.com
|
87
87
|
executables:
|
88
|
-
-
|
88
|
+
- another_toy_robot
|
89
89
|
extensions: []
|
90
90
|
extra_rdoc_files: []
|
91
91
|
files:
|
@@ -97,27 +97,27 @@ files:
|
|
97
97
|
- LICENSE.txt
|
98
98
|
- README.md
|
99
99
|
- Rakefile
|
100
|
+
- another_toy_robot.gemspec
|
101
|
+
- bin/another_toy_robot
|
100
102
|
- bin/console
|
101
103
|
- bin/setup
|
102
|
-
-
|
103
|
-
- lib/
|
104
|
-
- lib/
|
105
|
-
- lib/
|
106
|
-
- lib/
|
107
|
-
- lib/
|
108
|
-
- lib/
|
109
|
-
- lib/
|
110
|
-
- lib/
|
111
|
-
- lib/
|
112
|
-
- lib/
|
113
|
-
- lib/
|
114
|
-
- lib/
|
115
|
-
- lib/
|
116
|
-
- lib/
|
117
|
-
- lib/
|
118
|
-
|
119
|
-
- toy_robot.gemspec
|
120
|
-
homepage: https://github.com/drzel/toy_robot
|
104
|
+
- lib/another_toy_robot.rb
|
105
|
+
- lib/another_toy_robot/arena.rb
|
106
|
+
- lib/another_toy_robot/client.rb
|
107
|
+
- lib/another_toy_robot/command.rb
|
108
|
+
- lib/another_toy_robot/direction.rb
|
109
|
+
- lib/another_toy_robot/input.rb
|
110
|
+
- lib/another_toy_robot/invalid_command.rb
|
111
|
+
- lib/another_toy_robot/left_command.rb
|
112
|
+
- lib/another_toy_robot/move_command.rb
|
113
|
+
- lib/another_toy_robot/null_position.rb
|
114
|
+
- lib/another_toy_robot/place_command.rb
|
115
|
+
- lib/another_toy_robot/position.rb
|
116
|
+
- lib/another_toy_robot/report_command.rb
|
117
|
+
- lib/another_toy_robot/right_command.rb
|
118
|
+
- lib/another_toy_robot/robot.rb
|
119
|
+
- lib/another_toy_robot/version.rb
|
120
|
+
homepage: https://github.com/drzel/another_toy_robot
|
121
121
|
licenses:
|
122
122
|
- MIT
|
123
123
|
metadata: {}
|
data/bin/toy_robot
DELETED
data/lib/toy_robot/version.rb
DELETED