loco_bot 2.0.0 → 2.0.1

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: 5bcc03fc9e471fbe3836c3d97c8f4b2c1781c3b4
4
- data.tar.gz: 3422b70bf9684df8760c86aee333509d3c3ea18f
3
+ metadata.gz: 6e0a1c8db7a70dcd7daec9e1493e617a4ef3d912
4
+ data.tar.gz: 1f9d8d45a358faf58a8dba65af42f9fd9b553581
5
5
  SHA512:
6
- metadata.gz: f6e1f94945da2600e5d87060c1d86a38609e38b762c2b270a2f603306b7bd762aa93883a1b6627d82a9a545d6f5a07471337a266bb1af7b4b11c1141f5a8a4d5
7
- data.tar.gz: 1a543d54eb4229da4fe29d915b1f4f9251d31e9d9b56f76d34807d611193cfcec09c9cc3e2b1f60338d934224669109cf8ab08bea020c7c78acda7ef30f5b053
6
+ metadata.gz: c6b6cbecc758ad45feda6b9c9bcfda1261afe32bc449c380e07d9db4c5582acff2240ea65454750a4eec31559a48bc6f73c7b6fef6225cf403b70001c853ebaa
7
+ data.tar.gz: 1753fbf0dc832a2d1d3418eae6bf5450c39b36a79f2162691d8223c56e7dac7ee37bea6c52e16dfdc3f6a42f9e2ac3648f02108e511da86e85404ee51773fb39
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Metrics/LineLength:
2
+ Max: 120
data/Rakefile CHANGED
@@ -3,7 +3,16 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new('spec')
5
5
 
6
+ begin
7
+ require 'rubocop/rake_task'
8
+ RuboCop::RakeTask.new do |task|
9
+ task.options = ['-D']
10
+ end
11
+ rescue LoadError
12
+ warn 'Rubocop not found'
13
+ end
14
+
6
15
  task default: :test
7
16
 
8
17
  desc 'Run the test suite'
9
- task test: :spec
18
+ task test: [:spec, :rubocop]
data/bin/loco_bot_cli CHANGED
@@ -5,6 +5,6 @@ require 'loco_bot'
5
5
 
6
6
  cli = LocoBot::CLI.new
7
7
 
8
- while input = STDIN.gets
8
+ while (input = STDIN.gets)
9
9
  cli.input!(input)
10
10
  end
@@ -3,7 +3,6 @@ module LocoBot
3
3
  module Command
4
4
  # Parent class for Command classes.
5
5
  class Base
6
-
7
6
  # @!attribute [r] table
8
7
  # @return [Robot] the Robot
9
8
  attr_reader :robot
@@ -20,7 +19,7 @@ module LocoBot
20
19
  # Returns the Command's label.
21
20
  # @return [String] the Command's label
22
21
  def self.label
23
- self.name.split("::").last.upcase
22
+ name.split('::').last.upcase
24
23
  end
25
24
  end
26
25
  end
@@ -6,11 +6,19 @@ module LocoBot
6
6
  # Executes the command.
7
7
  # @return [void]
8
8
  def execute
9
- report = robot.report
9
+ report_hash = robot.report
10
10
 
11
- unless report.empty?
12
- puts "#{report[:x]},#{report[:y]},#{report[:direction].label}"
13
- end
11
+ puts report_string(report_hash) unless report_hash.empty?
12
+ end
13
+
14
+ private
15
+
16
+ def report_string(report_hash)
17
+ [
18
+ report_hash[:x],
19
+ report_hash[:y],
20
+ report_hash[:direction].label
21
+ ].join(',')
14
22
  end
15
23
  end
16
24
  end
@@ -10,11 +10,10 @@ module LocoBot
10
10
  class CLI
11
11
  # Top-level namespace for available commands.
12
12
  module Command
13
-
14
13
  # Returns the list of available commands.
15
14
  # @return [Array<String>] the list of available commands
16
15
  def self.list
17
- list = constants.map {|const| const.to_s.upcase}
16
+ list = constants.map { |const| const.to_s.upcase }
18
17
  list.delete('BASE')
19
18
  list
20
19
  end
@@ -23,11 +22,9 @@ module LocoBot
23
22
  # @param name [String] the Command name
24
23
  # @return [Command] the Command
25
24
  def self.class_from_name(name)
26
- return nil if name.nil? or name.capitalize.to_s == 'Base'
25
+ return nil if name.nil? || name.capitalize.to_s == 'Base'
27
26
 
28
- if const_defined?(name.capitalize, false)
29
- const_get(name.capitalize)
30
- end
27
+ const_get(name.capitalize) if const_defined?(name.capitalize, false)
31
28
  end
32
29
  end
33
30
  end
data/lib/loco_bot/cli.rb CHANGED
@@ -46,11 +46,9 @@ module LocoBot
46
46
  private
47
47
 
48
48
  def execute_command(command_class, arguments)
49
- begin
50
- command_class.new(robot, table).execute(*arguments)
51
- rescue ArgumentError => exception
52
- puts "#{command_class.label}: #{exception.message}"
53
- end
49
+ command_class.new(robot, table).execute(*arguments)
50
+ rescue ArgumentError => exception
51
+ puts "#{command_class.label}: #{exception.message}"
54
52
  end
55
53
 
56
54
  def parse_input(input)
@@ -3,7 +3,6 @@ module LocoBot
3
3
  module Direction
4
4
  # East direction.
5
5
  module East
6
-
7
6
  # Returns the Direction at the left of this one.
8
7
  # @return [Direction::North]
9
8
  def self.left
@@ -3,7 +3,6 @@ module LocoBot
3
3
  module Direction
4
4
  # North direction.
5
5
  module North
6
-
7
6
  # Returns the Direction at the left of this one.
8
7
  # @return [Direction::West]
9
8
  def self.left
@@ -3,7 +3,6 @@ module LocoBot
3
3
  module Direction
4
4
  # South direction.
5
5
  module South
6
-
7
6
  # Returns the Direction at the left of this one.
8
7
  # @return [Direction::East]
9
8
  def self.left
@@ -3,7 +3,6 @@ module LocoBot
3
3
  module Direction
4
4
  # West direction.
5
5
  module West
6
-
7
6
  # Returns the Direction at the left of this one.
8
7
  # @return [Direction::South]
9
8
  def self.left
@@ -7,7 +7,6 @@ module LocoBot
7
7
  class Robot
8
8
  # Top-level namespace for the possible facing directions.
9
9
  module Direction
10
-
11
10
  # Returns the list of available Direction as Strings.
12
11
  # @return [Array<String>]
13
12
  def self.list
@@ -18,9 +17,7 @@ module LocoBot
18
17
  # @param name [String] the Direction name
19
18
  # @return [Command] the Direction
20
19
  def self.from_name(name)
21
- if const_defined?(name.capitalize, false)
22
- const_get(name.capitalize)
23
- end
20
+ const_get(name.capitalize) if const_defined?(name.capitalize, false)
24
21
  end
25
22
  end
26
23
  end
@@ -3,7 +3,6 @@ require 'loco_bot/robot/direction'
3
3
  module LocoBot
4
4
  # Representation of a robot, placeable on tables.
5
5
  class Robot
6
-
7
6
  # @!attribute [r] table
8
7
  # @return [Table] the Table the Robot is currently placed on
9
8
  attr_reader :table
@@ -78,7 +77,7 @@ module LocoBot
78
77
  def report
79
78
  return {} if table.nil?
80
79
 
81
- {x: x, y: y, direction: direction}
80
+ { x: x, y: y, direction: direction }
82
81
  end
83
82
 
84
83
  # Outputs a friendly greating.
@@ -1,7 +1,6 @@
1
1
  module LocoBot
2
2
  # Representation of a table on which robots can be placed.
3
3
  class Table
4
-
5
4
  # @!attribute [r] width
6
5
  # @return [Fixnum] width of the Table
7
6
  # Determines the farthest accessible point on the Table's x-axis.
@@ -65,7 +64,7 @@ module LocoBot
65
64
  # @param y [Integer] the y-axis coordinate
66
65
  # @return [Boolean] true if a Robot can be placed at the given coordinates, false otherwise.
67
66
  def position_valid?(x, y)
68
- position_within_bounds?(x, y) and position_free?(x, y)
67
+ position_within_bounds?(x, y) && position_free?(x, y)
69
68
  end
70
69
 
71
70
  # The collection of Robots currently placed on the Table.
@@ -81,7 +80,7 @@ module LocoBot
81
80
  end
82
81
 
83
82
  def position_free?(x, y)
84
- robots.none? {|robot| robot.x == x && robot.y == y }
83
+ robots.none? { |robot| robot.x == x && robot.y == y }
85
84
  end
86
85
 
87
86
  def validate_dimensions
@@ -89,7 +88,7 @@ module LocoBot
89
88
  errors << "#{width} is not a valid width: it must be > 0" unless width > 0
90
89
  errors << "#{height} is not a valid height: it must be > 0" unless height > 0
91
90
 
92
- raise ArgumentError.new(errors.join(', ')) unless errors.empty?
91
+ fail(ArgumentError, errors.join(', ')) unless errors.empty?
93
92
  end
94
93
  end
95
94
  end
@@ -1,4 +1,5 @@
1
+ # Top-level namespace of the gem.
1
2
  module LocoBot
2
3
  # The gem's current version
3
- VERSION = '2.0.0'
4
+ VERSION = '2.0.1'
4
5
  end
data/loco_bot.gemspec CHANGED
@@ -8,8 +8,10 @@ Gem::Specification.new do |spec|
8
8
  spec.version = LocoBot::VERSION
9
9
  spec.authors = ['Rafaël Gonzalez']
10
10
  spec.email = ['github@rafaelgonzalez.me']
11
- spec.summary = %q{Ruby gem of crazy robots and benevolent tables that keep watching over them.}
12
- spec.description = %q{Issue commands to control the robots and the tables will keep you from making them fall, you monster!}
11
+ spec.summary = 'Ruby gem of crazy robots and benevolent tables that ' \
12
+ 'keep watching over them.'
13
+ spec.description = 'Issue commands to control the robots and the tables ' \
14
+ 'will keep you from making them fall, you monster!'
13
15
  spec.homepage = 'https://github.com/rafaelgonzalez/loco_bot'
14
16
  spec.license = 'MIT'
15
17
 
@@ -23,4 +25,5 @@ Gem::Specification.new do |spec|
23
25
  spec.add_development_dependency 'rspec', '~> 3.0'
24
26
  spec.add_development_dependency 'simplecov', '~> 0.9'
25
27
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.0'
28
+ spec.add_development_dependency 'rubocop', '~> 0.32.1'
26
29
  end
@@ -12,7 +12,7 @@ RSpec.describe LocoBot::CLI::Command::Report do
12
12
  end
13
13
 
14
14
  context 'after placing robot' do
15
- before { subject.robot.place(table, 4 ,2 , LocoBot::Robot::Direction::East) }
15
+ before { subject.robot.place(table, 4, 2, LocoBot::Robot::Direction::East) }
16
16
 
17
17
  it 'outputs a string' do
18
18
  expect { subject.execute }.to output("4,2,EAST\n").to_stdout
@@ -2,7 +2,7 @@ RSpec.describe LocoBot::CLI::Command do
2
2
  describe '.list' do
3
3
  subject { described_class.list }
4
4
 
5
- it { is_expected.to eql ['HODOR', 'LEFT', 'MOVE', 'PLACE', 'REPORT', 'RIGHT'] }
5
+ it { is_expected.to eql %w(HODOR LEFT MOVE PLACE REPORT RIGHT) }
6
6
  end
7
7
 
8
8
  describe '.class_from_name' do
@@ -17,9 +17,9 @@ RSpec.describe LocoBot::CLI do
17
17
  let(:command_class_double) { double }
18
18
 
19
19
  it 'calls the correct command' do
20
- expect(LocoBot::CLI::Command::Place).to receive(:new).
21
- with(subject.robot, subject.table).
22
- once.and_return(command_class_double)
20
+ expect(LocoBot::CLI::Command::Place).to receive(:new)
21
+ .with(subject.robot, subject.table)
22
+ .once.and_return(command_class_double)
23
23
 
24
24
  expect(command_class_double).to receive(:execute).with('1', '3', 'SOUTH').once
25
25
 
@@ -41,7 +41,9 @@ RSpec.describe LocoBot::CLI do
41
41
  let(:arguments) { '' }
42
42
 
43
43
  it 'does not raise an error' do
44
- expect { subject.input!(input) }.to output("YADAYADA: not a known command. Valid commands are HODOR, LEFT, MOVE, PLACE, REPORT, RIGHT.\n").to_stdout
44
+ expect { subject.input!(input) }.to output(
45
+ "YADAYADA: not a known command. Valid commands are HODOR, LEFT, MOVE, PLACE, REPORT, RIGHT.\n"
46
+ ).to_stdout
45
47
  end
46
48
  end
47
49
  end
@@ -20,6 +20,6 @@ RSpec.describe LocoBot::Robot::Direction::East do
20
20
  describe '.vector' do
21
21
  subject { described_class.vector(21, 17) }
22
22
 
23
- it { is_expected.to eql({ x: 22, y: 17 }) }
23
+ it { is_expected.to eql(x: 22, y: 17) }
24
24
  end
25
25
  end
@@ -20,6 +20,6 @@ RSpec.describe LocoBot::Robot::Direction::North do
20
20
  describe '.vector' do
21
21
  subject { described_class.vector(21, 17) }
22
22
 
23
- it { is_expected.to eql({ x: 21, y: 18 }) }
23
+ it { is_expected.to eql(x: 21, y: 18) }
24
24
  end
25
25
  end
@@ -20,6 +20,6 @@ RSpec.describe LocoBot::Robot::Direction::South do
20
20
  describe '.vector' do
21
21
  subject { described_class.vector(21, 17) }
22
22
 
23
- it { is_expected.to eql({ x: 21, y: 16 }) }
23
+ it { is_expected.to eql(x: 21, y: 16) }
24
24
  end
25
25
  end
@@ -20,6 +20,6 @@ RSpec.describe LocoBot::Robot::Direction::West do
20
20
  describe '.vector' do
21
21
  subject { described_class.vector(21, 17) }
22
22
 
23
- it { is_expected.to eql({ x: 20, y: 17 }) }
23
+ it { is_expected.to eql(x: 20, y: 17) }
24
24
  end
25
25
  end
@@ -2,7 +2,7 @@ RSpec.describe LocoBot::Robot::Direction do
2
2
  describe '.list' do
3
3
  subject { described_class.list }
4
4
 
5
- it { is_expected.to eql ['East', 'North', 'South', 'West'] }
5
+ it { is_expected.to eql %w(East North South West) }
6
6
  end
7
7
 
8
8
  describe '.from_name' do
@@ -272,7 +272,7 @@ RSpec.describe LocoBot::Robot do
272
272
  context 'when placed on a table' do
273
273
  before { robot.place(table, 6, 17, LocoBot::Robot::Direction::East) }
274
274
 
275
- it { is_expected.to eql({x: 6, y: 17, direction: LocoBot::Robot::Direction::East}) }
275
+ it { is_expected.to eql(x: 6, y: 17, direction: LocoBot::Robot::Direction::East) }
276
276
  end
277
277
 
278
278
  context 'when not placed on a table' do
@@ -300,25 +300,25 @@ RSpec.describe LocoBot::Robot do
300
300
  context 'facing north' do
301
301
  let(:direction) { LocoBot::Robot::Direction::North }
302
302
 
303
- it { is_expected.to eql({x: 10, y: 11}) }
303
+ it { is_expected.to eql(x: 10, y: 11) }
304
304
  end
305
305
 
306
306
  context 'facing south' do
307
307
  let(:direction) { LocoBot::Robot::Direction::South }
308
308
 
309
- it { is_expected.to eql({x: 10, y: 9}) }
309
+ it { is_expected.to eql(x: 10, y: 9) }
310
310
  end
311
311
 
312
312
  context 'facing east' do
313
313
  let(:direction) { LocoBot::Robot::Direction::East }
314
314
 
315
- it { is_expected.to eql({x: 11, y: 10}) }
315
+ it { is_expected.to eql(x: 11, y: 10) }
316
316
  end
317
317
 
318
318
  context 'facing west' do
319
319
  let(:direction) { LocoBot::Robot::Direction::West }
320
320
 
321
- it { is_expected.to eql({x: 9, y: 10}) }
321
+ it { is_expected.to eql(x: 9, y: 10) }
322
322
  end
323
323
  end
324
324
  end
@@ -330,7 +330,6 @@ RSpec.describe LocoBot::Robot do
330
330
  it { is_expected.to be false }
331
331
  end
332
332
 
333
-
334
333
  context 'when placed on a table' do
335
334
  before { robot.place(table, 0, 0, direction) }
336
335
 
@@ -11,20 +11,20 @@ RSpec.describe LocoBot::Table do
11
11
  context 'with an invalid width' do
12
12
  let(:width) { 0 }
13
13
 
14
- it { expect{ subject }.to(raise_error(ArgumentError)) }
14
+ it { expect { subject }.to(raise_error(ArgumentError)) }
15
15
  end
16
16
 
17
17
  context 'with an invalid height' do
18
18
  let(:height) { -5 }
19
19
 
20
- it { expect{ subject }.to(raise_error(ArgumentError)) }
20
+ it { expect { subject }.to(raise_error(ArgumentError)) }
21
21
  end
22
22
 
23
23
  context 'with an invalid width and height' do
24
24
  let(:width) { -16 }
25
25
  let(:height) { 0 }
26
26
 
27
- it { expect{ subject }.to(raise_error(ArgumentError)) }
27
+ it { expect { subject }.to(raise_error(ArgumentError)) }
28
28
  end
29
29
  end
30
30
 
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,7 @@ CodeClimate::TestReporter.start
3
3
 
4
4
  require 'simplecov'
5
5
  SimpleCov.start do
6
- add_filter "/spec/"
6
+ add_filter '/spec/'
7
7
  end
8
8
 
9
9
  require 'loco_bot'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loco_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafaël Gonzalez
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.4.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.32.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.32.1
83
97
  description: Issue commands to control the robots and the tables will keep you from
84
98
  making them fall, you monster!
85
99
  email:
@@ -91,6 +105,7 @@ extra_rdoc_files: []
91
105
  files:
92
106
  - ".gitignore"
93
107
  - ".rspec"
108
+ - ".rubocop.yml"
94
109
  - ".travis.yml"
95
110
  - Gemfile
96
111
  - LICENSE.txt