robojora 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49bb8a26a341996273ea81d944a2de3f60c61c4958bb61cc4b8a66524021afcf
4
- data.tar.gz: 8bb791fc706555bae991368918f7ebb85e9750a7da2da9836afd9b8c97e2c9d4
3
+ metadata.gz: b72ba8db6436c7677b7600cb6fc1fc24d81e75599bbf44524fdcf325e72ee2d5
4
+ data.tar.gz: 833d8299767fbbab25b5fbe62ca0f345ded2da13de99b1fca65692b3b1b6ecfe
5
5
  SHA512:
6
- metadata.gz: 1defbf0a9b6f16d7b104bcf4b5a72c14a8eb1c4effd1eefe0f3407380dfef5f1ca1a752a6f071d93416ef47ccab2608bbdaaf15c8c9fc63d4eafca7fae62f9aa
7
- data.tar.gz: 571930d287b3d186adc0474671ef5f68fe6e4bd04eccacf1aeadcdcba1cafec71100f9efe650f4cfd717a240a97d73a44acf78b827729b448498dc6bf3dbd1c1
6
+ metadata.gz: aa8faecc15c1ae3d63fd2c457ec14d261187681b042b253eb3a4fd7cc10eaa72f9e73853c863a947d574cd15515624f48d125ef304a7126e28c8826377ce92fc
7
+ data.tar.gz: 89760a6fe8ec19fe75ac08ea29eb6669ce3538882556e58d35f0aabb054f8108fa948e283d806990cbae4227922c897fdf87d67213fe10b6c91ed476f8fc1c16
data/Gemfile.lock CHANGED
@@ -6,12 +6,7 @@ PATH
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- coderay (1.1.2)
10
9
  diff-lcs (1.3)
11
- method_source (0.9.2)
12
- pry (0.12.2)
13
- coderay (~> 1.1.0)
14
- method_source (~> 0.9.0)
15
10
  rake (10.5.0)
16
11
  rspec (3.9.0)
17
12
  rspec-core (~> 3.9.0)
@@ -32,7 +27,6 @@ PLATFORMS
32
27
 
33
28
  DEPENDENCIES
34
29
  bundler (~> 2.0)
35
- pry (~> 0.12.2)
36
30
  rake (~> 10.0)
37
31
  robojora!
38
32
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,12 +1,24 @@
1
+ ![robojora-robot](https://github.com/enriquesalceda/robojora/blob/master/smaller_robot.png)
2
+
1
3
  # Robojora
4
+ [![Build Status](https://travis-ci.com/enriquesalceda/robojora.svg?branch=master)](https://travis-ci.com/enriquesalceda/robojora)
2
5
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/robojora`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+ This is Enrique's Jora robot challenge. I have created a gem called `Robojora`
7
+ that contains:
4
8
 
5
- TODO: Delete this and the text above, and describe your gem
9
+ - The logic required by the challenge.
10
+ - Automated testing.
11
+ - CI integration with Travis.
6
12
 
7
13
  ## Installation
8
14
 
9
- Add this line to your application's Gemfile:
15
+ If you are going to test locally, I recommend you to:
16
+
17
+ ```shell
18
+ $ gem install robojora
19
+ ```
20
+
21
+ Or, if you want to add this to an app:
10
22
 
11
23
  ```ruby
12
24
  gem 'robojora'
@@ -14,25 +26,57 @@ gem 'robojora'
14
26
 
15
27
  And then execute:
16
28
 
17
- $ bundle
29
+ ```shell
30
+ $ bundle
31
+ ```
18
32
 
19
- Or install it yourself as:
33
+ ## Usage
20
34
 
21
- $ gem install robojora
35
+ Let's say you ran `gem install robojora`, now you can:
22
36
 
23
- ## Usage
37
+ * Go to pry
24
38
 
25
- TODO: Write usage instructions here
39
+ ```shell
40
+ $ pry
41
+ ```
26
42
 
27
- ## Development
43
+ * Require `robojora`
44
+ ```shell
45
+ > require 'robojora'
46
+ ```
28
47
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+ From here you can start testing the code. First of all you have to build a board
49
+ like this:
30
50
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+ ```ruby
52
+ full_board = Robojora::Board.new.build
53
+ ```
32
54
 
33
- ## Contributing
55
+ Then, create a robot like this:
34
56
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/robojora.
57
+ ```ruby
58
+ robot = Robojora::Robot.new('tars')
59
+ ```
60
+
61
+ Now, tars can start playing a board like this:
62
+
63
+ ```ruby
64
+ robot.play_board(full_board)
65
+ ```
66
+
67
+ From here you can start placing the robot like this:
68
+
69
+ ```ruby
70
+ robot.place(3, 3, 'north')
71
+ ```
72
+
73
+ And then, you can continue rotating, moving, and reporting the report!
74
+
75
+ ```ruby
76
+ robot.left
77
+ robot.move
78
+ robot.report
79
+ ```
36
80
 
37
81
  ## License
38
82
 
@@ -1,13 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Robojora
4
2
  class Board
5
- MINIMUM_AXIS_VALUE = 0
6
- MAXIMUM_AXIS_VALUE = 4
7
-
8
3
  def initialize
9
- @minimum_axis_value = MINIMUM_AXIS_VALUE
10
- @maximum_axis_value = MAXIMUM_AXIS_VALUE
4
+ @minimum_axis_value = Robojora::Settings.minimum_axis_value
5
+ @maximum_axis_value = Robojora::Settings.maximum_axis_value
11
6
  end
12
7
 
13
8
  def build
@@ -1,7 +1,5 @@
1
1
  module Robojora
2
2
  class BorderClassifier
3
- MINIMUM_AXIS_VALUE = 0
4
- MAXIMUM_AXIS_VALUE = 4
5
3
 
6
4
  attr_reader :borders, :coordinates
7
5
 
@@ -21,19 +19,19 @@ module Robojora
21
19
  private
22
20
 
23
21
  def assign_to_north_border_if_north_coordinate
24
- borders << 'north' if coordinates.last == MAXIMUM_AXIS_VALUE
22
+ borders << Robojora::Settings.north if coordinates.last == Robojora::Settings.maximum_axis_value
25
23
  end
26
24
 
27
25
  def assign_to_west_border_if_west_coordinate
28
- borders << 'west' if coordinates.first == MINIMUM_AXIS_VALUE
26
+ borders << Robojora::Settings.west if coordinates.first == Robojora::Settings.minimum_axis_value
29
27
  end
30
28
 
31
29
  def assign_to_south_border_if_south_coordinate
32
- borders << 'south' if coordinates.last == MINIMUM_AXIS_VALUE
30
+ borders << Robojora::Settings.south if coordinates.last == Robojora::Settings.minimum_axis_value
33
31
  end
34
32
 
35
33
  def assign_to_east_border_if_east_coordinate
36
- borders << 'east' if coordinates.first == MAXIMUM_AXIS_VALUE
34
+ borders << Robojora::Settings.east if coordinates.first == Robojora::Settings.maximum_axis_value
37
35
  end
38
36
  end
39
37
  end
@@ -1,7 +1,7 @@
1
- require 'pry'
2
1
  module Robojora
3
2
  class Robot
4
3
  NOT_IN_BOARD = 'Robot is not on the board'.freeze
4
+ private_constant :NOT_IN_BOARD
5
5
 
6
6
  attr_reader :board, :name
7
7
  attr_accessor :facing
@@ -16,6 +16,9 @@ module Robojora
16
16
  end
17
17
 
18
18
  def place(x_coordinate, y_coordinate, facing)
19
+ raise ArgumentError, 'x_coordinate and y_coordinate must be integers' unless x_coordinate.is_a?(Integer) && y_coordinate.is_a?(Integer)
20
+ raise CardinalDirectionError, 'facing should be a cardinal point string' unless Robojora::Settings.cardinal_points.include?(facing) || !select_square_by_name.nil?
21
+
19
22
  square = select_square_by_coordinates(x_coordinate, y_coordinate)
20
23
  robot_removing_and_placing(facing, square) if square
21
24
  end
@@ -33,7 +36,7 @@ module Robojora
33
36
  end
34
37
 
35
38
  def move
36
- raise Robojora::RobotNotOnBoardError if select_square_by_name.nil?
39
+ raise Robojora::RobotNotOnBoardError if not_movable?
37
40
 
38
41
  mover.move
39
42
  end
@@ -50,6 +53,7 @@ module Robojora
50
53
  remove_robot_from_current_square
51
54
  self.facing ||= facing
52
55
  square.presence = name
56
+ true
53
57
  end
54
58
 
55
59
  private
@@ -70,5 +74,9 @@ module Robojora
70
74
  def mover
71
75
  Robojora::Movers.const_get(facing.capitalize).new(self)
72
76
  end
77
+
78
+ def not_movable?
79
+ select_square_by_name.nil? || select_square_by_name.borders.include?(facing)
80
+ end
73
81
  end
74
82
  end
@@ -1,7 +1,9 @@
1
1
  module Robojora
2
2
  class Rotator
3
- CARDINAL_POINTS_FOR_LEFT = %w[north west south east north].freeze
4
- CARDINAL_POINTS_FOR_RIGHT = CARDINAL_POINTS_FOR_LEFT.reverse.freeze
3
+ LEFT = (Robojora::Settings.cardinal_points + [Robojora::Settings.north]).freeze
4
+ RIGHT = LEFT.reverse.freeze
5
+
6
+ private_constant :LEFT, :RIGHT
5
7
 
6
8
  attr_reader :initial_direction
7
9
 
@@ -10,21 +12,21 @@ module Robojora
10
12
  end
11
13
 
12
14
  def left
13
- CARDINAL_POINTS_FOR_LEFT.fetch(left_desired_cardinal_direction_index)
15
+ LEFT.fetch(left_desired_cardinal_direction_index)
14
16
  end
15
17
 
16
18
  def right
17
- CARDINAL_POINTS_FOR_RIGHT.fetch(right_desired_cardinal_direction_index)
19
+ RIGHT.fetch(right_desired_cardinal_direction_index)
18
20
  end
19
21
 
20
22
  private
21
23
 
22
24
  def left_desired_cardinal_direction_index
23
- CARDINAL_POINTS_FOR_LEFT.index(initial_direction) + 1
25
+ LEFT.index(initial_direction) + 1
24
26
  end
25
27
 
26
28
  def right_desired_cardinal_direction_index
27
- CARDINAL_POINTS_FOR_RIGHT.index(initial_direction) + 1
29
+ RIGHT.index(initial_direction) + 1
28
30
  end
29
31
  end
30
32
  end
@@ -0,0 +1,45 @@
1
+ module Robojora
2
+ class Settings
3
+ MINIMUM_AXIS_VALUE = 0
4
+ MAXIMUM_AXIS_VALUE = 4
5
+
6
+ NORTH = 'north'.freeze
7
+ WEST = 'west'.freeze
8
+ SOUTH = 'south'.freeze
9
+ EAST = 'east'.freeze
10
+
11
+ CARDINAL_POINTS = [NORTH, WEST, SOUTH, EAST].freeze
12
+
13
+
14
+ private_constant :NORTH, :WEST, :SOUTH, :EAST, :CARDINAL_POINTS,
15
+ :MINIMUM_AXIS_VALUE, :MAXIMUM_AXIS_VALUE
16
+
17
+ def self.minimum_axis_value
18
+ MINIMUM_AXIS_VALUE
19
+ end
20
+
21
+ def self.maximum_axis_value
22
+ MAXIMUM_AXIS_VALUE
23
+ end
24
+
25
+ def self.cardinal_points
26
+ CARDINAL_POINTS
27
+ end
28
+
29
+ def self.north
30
+ NORTH
31
+ end
32
+
33
+ def self.west
34
+ WEST
35
+ end
36
+
37
+ def self.south
38
+ SOUTH
39
+ end
40
+
41
+ def self.east
42
+ EAST
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module Robojora
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
data/lib/robojora.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'robojora/version'
2
+ require 'robojora/settings'
2
3
  require 'robojora/board'
3
4
  require 'robojora/border_classifier'
4
5
  require 'robojora/square'
5
6
  require 'robojora/robot'
6
7
  require 'robojora/rotator'
7
- require 'robojora/cardinal_directions'
8
8
  require 'robojora/movers/mover'
9
9
  require 'robojora/movers/north'
10
10
  require 'robojora/movers/south'
@@ -13,4 +13,5 @@ require 'robojora/movers/east'
13
13
 
14
14
  module Robojora
15
15
  class RobotNotOnBoardError < StandardError; end
16
+ class CardinalDirectionError < StandardError; end
16
17
  end
data/robojora.gemspec CHANGED
@@ -28,6 +28,5 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_development_dependency 'bundler', '~> 2.0'
30
30
  spec.add_development_dependency 'rake', '~> 10.0'
31
- spec.add_development_dependency 'pry', '~> 0.12.2'
32
31
  spec.add_development_dependency 'rspec', '~> 3.0'
33
32
  end
data/smaller_robot.png ADDED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robojora
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrique Salceda
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: pry
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.12.2
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.12.2
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -85,7 +71,6 @@ files:
85
71
  - lib/robojora.rb
86
72
  - lib/robojora/board.rb
87
73
  - lib/robojora/border_classifier.rb
88
- - lib/robojora/cardinal_directions.rb
89
74
  - lib/robojora/movers/east.rb
90
75
  - lib/robojora/movers/mover.rb
91
76
  - lib/robojora/movers/north.rb
@@ -93,9 +78,11 @@ files:
93
78
  - lib/robojora/movers/west.rb
94
79
  - lib/robojora/robot.rb
95
80
  - lib/robojora/rotator.rb
81
+ - lib/robojora/settings.rb
96
82
  - lib/robojora/square.rb
97
83
  - lib/robojora/version.rb
98
84
  - robojora.gemspec
85
+ - smaller_robot.png
99
86
  homepage: https://github.com/enriquesalceda/robojora
100
87
  licenses:
101
88
  - MIT
@@ -1,15 +0,0 @@
1
- module Robojora
2
- class CardinalDirections
3
- CARDINAL_POINTS = %w[north west south east].freeze
4
-
5
- def self.all
6
- CARDINAL_POINTS
7
- end
8
-
9
- Robojora::CardinalDirections::CARDINAL_POINTS.each do |cardinal_point|
10
- define_singleton_method(:"#{cardinal_point}") do
11
- "#{state.upcase}"
12
- end
13
- end
14
- end
15
- end