robotoy 0.1.2 → 0.2.0

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
  SHA1:
3
- metadata.gz: 7a1c9bb9fae174ab82babcfe29b7387d2fc8aa9d
4
- data.tar.gz: 3537d4475db971f91c00385b5800cf2d820cd389
3
+ metadata.gz: c60b7489b010f57365859629723e0019d4dbe738
4
+ data.tar.gz: d862f6f91f4585c58e669de14da32777c58b781f
5
5
  SHA512:
6
- metadata.gz: 5d6662c098a0172e1e1d0a66c7ca0991c201781e8bc93e1bd8ca317b99c04eebab3510b1db09641c72e28bb434e75c8e8069769b61a497523cf1cdac44fcb207
7
- data.tar.gz: 693ef65396d6b25a066bdfe82571220f16122b8175b0e5332e84d7e1ef46ae847bd428fd04533a18ed1599e98cd51fc549299c934c2294ee09a79fb717ace1fb
6
+ metadata.gz: b5529734b3e6eae9cd87bdc74459fc1b701cc7d8253c9ce28aad941f68729468760debf157228f7438ae0952a349a670f14587d2cd2129999a973abc20a6a548
7
+ data.tar.gz: 048de6b5917fe2958ea34bc42673472a204c67ec41167131580f6cd6a356c3ad829172780ae4d45091f3fae0454ca5f96703e8d2931110463032a513926b6891
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  [![Build Status](https://travis-ci.org/hosseintoussi/robotoy.svg?branch=master)](https://travis-ci.org/hosseintoussi/robotoy)
2
2
  [![Gem Version](https://badge.fury.io/rb/robotoy.svg)](https://badge.fury.io/rb/robotoy)
3
+ [![Code Climate](https://codeclimate.com/github/hosseintoussi/robotoy/badges/gpa.svg)](https://codeclimate.com/github/hosseintoussi/robotoy)
4
+ [![Test Coverage](https://codeclimate.com/github/hosseintoussi/robotoy/badges/coverage.svg)](https://codeclimate.com/github/hosseintoussi/robotoy/coverage)
3
5
  # Robotoy
4
6
  - The application is a simulation of a toy robot moving on a square tabletop, of dimensions 5 units x 5 units.
5
7
  - There are no other obstructions on the table surface.
@@ -2,7 +2,8 @@ move
2
2
  tests
3
3
  PLACE 0,0,NORTH
4
4
  MOVE
5
- MOVE
5
+ report
6
+ MOVE 2
6
7
  REPORT
7
8
  RIGHT
8
9
  MOVE
@@ -12,8 +12,8 @@ module Robotoy
12
12
  puts command
13
13
  set_params(command)
14
14
  @game.perform(@method, @args)
15
- rescue
16
- puts "Something went wrong"
15
+ rescue Errors => e
16
+ puts e.message
17
17
  end
18
18
  end
19
19
  end
@@ -23,7 +23,7 @@ module Robotoy
23
23
  def set_params(command)
24
24
  splitted = command.split(/\s+/)
25
25
  @method = splitted[0].strip
26
- @args = splitted[1].split(',').map(&:strip) if splitted[1]
26
+ @args = splitted[1] ? splitted[1].split(',').map(&:strip) : []
27
27
  end
28
28
  end
29
29
  end
@@ -1,7 +1,31 @@
1
1
  module Robotoy
2
- class Errors < StandardError; end
3
- class NotValidOrientationError < Errors; end
4
- class NotValidMoveError < Errors; end
5
- class NotPlacedError < Errors; end
6
- class NotValidMethodError < Errors; end
2
+ class Errors < StandardError
3
+ def message
4
+ "hmm.. Not sure what happened there!"
5
+ end
6
+ end
7
+
8
+ class NotValidOrientationError < Errors
9
+ def message
10
+ "It looks like your Robot did not know there's such oriencation!"
11
+ end
12
+ end
13
+
14
+ class NotValidMoveError < Errors
15
+ def message
16
+ "It wasn't a valid move, unfortunately!"
17
+ end
18
+ end
19
+
20
+ class NotPlacedError < Errors
21
+ def message
22
+ "Your Robot is not placed yet!"
23
+ end
24
+ end
25
+
26
+ class NotValidMethodError < Errors
27
+ def message
28
+ "I don't understand what you want me to do! :("
29
+ end
30
+ end
7
31
  end
@@ -11,40 +11,31 @@ module Robotoy
11
11
 
12
12
  def perform(method, *args)
13
13
  send(method.downcase, *args.flatten)
14
- @action.perform
15
- rescue NotValidMoveError
16
- puts "Not a valid place unfortunately"
17
- rescue NotValidOrientationError
18
- puts "Not a valid orientation unfortunately"
19
- rescue NotPlacedError
20
- puts "Not placed yet"
21
- rescue NotValidMethodError
22
- puts "Not a valid method"
23
14
  end
24
15
 
25
16
  private
26
17
 
27
18
  def place(x, y, orient)
28
- @action = @place.new(robot: @robot, table: @table, x: x, y: y, orient: orient)
19
+ @place.new(robot: @robot, table: @table, x: x, y: y, orient: orient).perform
29
20
  end
30
21
 
31
- def move(*_args)
32
- @action = @move.new(robot: @robot, table: @table)
22
+ def move(range = 1)
23
+ @move.new(robot: @robot, table: @table, range: range).perform
33
24
  end
34
25
 
35
- def left(*_args)
36
- @action = @orientation.new(robot: @robot, side: :left)
26
+ def left
27
+ @orientation.new(robot: @robot, side: :left).perform
37
28
  end
38
29
 
39
- def right(*_args)
40
- @action = @orientation.new(robot: @robot, side: :right)
30
+ def right
31
+ @orientation.new(robot: @robot, side: :right).perform
41
32
  end
42
33
 
43
- def report(*_args)
44
- @action = @report.new(robot: @robot)
34
+ def report(type = :console)
35
+ @report.new(robot: @robot, type: type).perform
45
36
  end
46
37
 
47
- def method_missing(name, *args)
38
+ def method_missing(_name, *_args)
48
39
  raise Robotoy::NotValidMethodError
49
40
  end
50
41
  end
@@ -1,11 +1,10 @@
1
1
  module Robotoy
2
2
  module Services
3
3
  class Move
4
- def initialize(robot:, table:, x_range: 1, y_range: 1)
4
+ def initialize(robot:, table:, range:)
5
5
  @robot = robot
6
6
  @table = table
7
- @x_range = x_range
8
- @y_range = y_range
7
+ @range = range.to_i
9
8
  end
10
9
 
11
10
  def perform
@@ -16,26 +15,26 @@ module Robotoy
16
15
  private
17
16
 
18
17
  def north
19
- @table.validate_next_position(y: @robot.y + @y_range)
20
- @robot.y += @y_range
18
+ @table.validate_next_position(y: @robot.y + @range)
19
+ @robot.y += @range
21
20
  end
22
21
 
23
22
  def south
24
- @table.validate_next_position(y: @robot.y - @y_range)
25
- @robot.y -= @y_range
23
+ @table.validate_next_position(y: @robot.y - @range)
24
+ @robot.y -= @range
26
25
  end
27
26
 
28
27
  def east
29
- @table.validate_next_position(x: @robot.x + @x_range)
30
- @robot.x += @x_range
28
+ @table.validate_next_position(x: @robot.x + @range)
29
+ @robot.x += @range
31
30
  end
32
31
 
33
32
  def west
34
- @table.validate_next_position(x: @robot.x - @x_range)
35
- @robot.x -= @x_range
33
+ @table.validate_next_position(x: @robot.x - @range)
34
+ @robot.x -= @range
36
35
  end
37
36
 
38
- def method_missing(name, *args)
37
+ def method_missing(_name, *_args)
39
38
  raise Robotoy::NotValidMethodError
40
39
  end
41
40
  end
@@ -1,19 +1,28 @@
1
1
  module Robotoy
2
2
  module Services
3
3
  class Report
4
- def initialize(robot:)
4
+ def initialize(robot:, type:)
5
5
  @robot = robot
6
+ @type = type
6
7
  end
7
8
 
8
- def perform(type: :string)
9
+ def perform
9
10
  @robot.validate_if_placed
10
- send(type)
11
+ send(@type)
11
12
  end
12
13
 
13
14
  private
14
15
 
16
+ def console
17
+ puts "Output: #{string}"
18
+ end
19
+
15
20
  def string
16
- puts "Output: #{@robot.x},#{@robot.y},#{@robot.orientation.upcase}"
21
+ "#{@robot.x},#{@robot.y},#{@robot.orientation.upcase}"
22
+ end
23
+
24
+ def method_missing(_name, *_args)
25
+ raise Robotoy::NotValidMethodError
17
26
  end
18
27
  end
19
28
  end
@@ -1,3 +1,3 @@
1
1
  module Robotoy
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robotoy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hosseintoussi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-31 00:00:00.000000000 Z
11
+ date: 2016-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 2.5.1
121
+ rubygems_version: 2.4.8
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: Toy Robot Ruby