lemmibot 0.2.0 → 0.2.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: 227fcd2e8c60d5da75e9c77c3790cc8f1d0329dd
4
- data.tar.gz: 128e3d7d894e5d8a7ba60e481778273347fb1c46
3
+ metadata.gz: d125d14ad12b0139f69af46b5051534ab07d8395
4
+ data.tar.gz: cd9242fa6928f0db371708a91aa157b8e2ba3ea9
5
5
  SHA512:
6
- metadata.gz: b06fd2ecf35b87301a1bd8f7ed021c3a8e6dfeb9eb265036b00c904c54fd0254eb860f89fe9b63e7a34a01935f25edaa3312deb5df2980488d93a605a92f01ad
7
- data.tar.gz: ce2fa468a77cbd5d56f09ea0a8335d28c31bbcdfc9399818b6f3b4f124511edd744ecba204f5ca894a708e923d3550390809f25acc92e4621748fc5d45b42e75
6
+ metadata.gz: 88f65fc237a1b5bc6daf3ba49a6b482b8da998beca9af597467d7db745521646498cbc049ecf0a1ebd7f9e33c146eb77ed2c5ad1b01d5bab2634aff4239db464
7
+ data.tar.gz: 5abc057800f629faa4870d9b88ab96a078a70247bf64f7528b41893f90957a3a9a7d757fbe6babd25324d87433a7e38d40e4a00b54682badfa5b694852cdd3da
data/.rubocop.yml CHANGED
@@ -8,3 +8,6 @@ Metrics/LineLength:
8
8
  # Do not prefix writer method names with set_
9
9
  Style/AccessorMethodName:
10
10
  Enabled: false
11
+ # Do not suppress exceptions
12
+ Lint/HandleExceptions:
13
+ Enabled: false
data/.travis.yml CHANGED
@@ -2,4 +2,8 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.4.1
5
+ - 2.3
6
+ - 2.2
7
+ - 2.1
8
+ - 2.0
5
9
  before_install: gem install bundler -v 1.15.3
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Lemmibot
2
+ [![Gem Version](https://badge.fury.io/rb/lemmibot.svg)](https://badge.fury.io/rb/lemmibot)
3
+ [![Build Status](https://travis-ci.org/ineffyble/lemmibot.svg)](https://travis-ci.org/ineffyble/lemmibot)
2
4
 
3
5
  A toy robot with better self-preservation instincts than a real lemming.
4
6
 
@@ -8,6 +10,11 @@ Install the gem from [RubyGems](https://rubygems.org/):
8
10
 
9
11
  $ gem install lemmibot
10
12
 
13
+ ### Compatibility
14
+
15
+ Lemmibot is continuously tested against the latest minor versions of Ruby 2.0 onwards,
16
+ and should run on any system running `ruby >= 2.0.0`.
17
+
11
18
  ## Usage
12
19
 
13
20
  Once installed, start an interactive bot interface:
data/lemmibot.gemspec CHANGED
@@ -5,21 +5,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'lemmibot/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = 'lemmibot'
9
- spec.version = Lemmibot::VERSION
10
- spec.authors = ['Effy Elden']
11
- spec.email = ['git@effy.is']
8
+ spec.name = 'lemmibot'
9
+ spec.version = Lemmibot::VERSION
10
+ spec.authors = ['Effy Elden']
11
+ spec.email = ['git@effy.is']
12
12
 
13
- spec.summary = 'A toy robot with better self-preservation instincts than a lemming'
14
- spec.homepage = 'https://github.com/ineffyble/lemmibot'
15
- spec.license = 'MIT'
13
+ spec.summary = 'A toy robot with better self-preservation instincts than a lemming'
14
+ spec.homepage = 'https://github.com/ineffyble/lemmibot'
15
+ spec.license = 'MIT'
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ spec.required_ruby_version = '>= 2.0.0'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
20
  f.match(%r{^(test|spec|features)/})
19
21
  end
20
- spec.bindir = 'exe'
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ['lib']
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
23
25
 
24
26
  spec.add_development_dependency 'bundler', '~> 1.15'
25
27
  spec.add_development_dependency 'rake', '~> 10.0'
data/lib/lemmibot/bot.rb CHANGED
@@ -1,56 +1,13 @@
1
1
  module Lemmibot
2
- # A simulated toy robot on a table top
2
+ # A simulated toy robot on a tabletop
3
3
  class Bot
4
- DIRECTIONS = %i[west north east south].freeze
5
- attr_reader :pos_x
6
- attr_reader :pos_y
7
- attr_reader :direction
8
- attr_reader :placed
9
-
10
4
  def initialize
11
- # Set the bot's position when instantiated
12
5
  @pos_x = 0
13
6
  @pos_y = 0
14
7
  @direction = :north
15
8
  @placed = false
16
9
  end
17
10
 
18
- def valid_direction?(direction)
19
- DIRECTIONS.include? direction
20
- end
21
-
22
- def set_direction(direction)
23
- # Set the bot to be facing a specified valid direction
24
- return false unless valid_direction? direction
25
- @direction = direction
26
- true
27
- end
28
-
29
- def valid_position?(position)
30
- position >= 0 && position <= 4
31
- end
32
-
33
- def set_position(axis, position)
34
- # Set the bot to a specified valid position on specified axis
35
- return false unless valid_position? position
36
- if axis == :x
37
- @pos_x = position
38
- else
39
- @pos_y = position
40
- end
41
- true
42
- end
43
-
44
- def change_position(axis, value)
45
- # Alter the bot's position on the table top
46
- new_position = if axis == :x
47
- @pos_x + value
48
- else
49
- @pos_y + value
50
- end
51
- set_position(axis, new_position)
52
- end
53
-
54
11
  def turn(relative_direction)
55
12
  # Rotate the bot 90 degrees to face another direction
56
13
  # TODO: Find a nicer way to find the new direction
@@ -79,12 +36,62 @@ module Lemmibot
79
36
  end
80
37
 
81
38
  def place(x, y, direction)
82
- # Places the bot at a specified position, facing specified direction
39
+ # Place the bot at a specified position, facing specified direction
83
40
  return false unless set_position(:x, x) &&
84
41
  set_position(:y, y) &&
85
42
  set_direction(direction)
86
43
  @placed = true
87
44
  true
88
45
  end
46
+
47
+ def report
48
+ # Return a hash of the bot's current location and direction
49
+ return false unless @placed
50
+ {
51
+ x: @pos_x,
52
+ y: @pos_y,
53
+ dir: @direction
54
+ }
55
+ end
56
+
57
+ private
58
+
59
+ DIRECTIONS = %i[west north east south].freeze
60
+
61
+ def valid_direction?(direction)
62
+ DIRECTIONS.include? direction
63
+ end
64
+
65
+ def set_direction(direction)
66
+ # Set the bot to be facing a specified valid direction
67
+ return false unless valid_direction? direction
68
+ @direction = direction
69
+ true
70
+ end
71
+
72
+ def valid_position?(position)
73
+ # Check if a position is on the tabletop
74
+ position >= 0 && position <= 4
75
+ end
76
+
77
+ def set_position(axis, position)
78
+ # Set the bot to a specified valid position on specified axis
79
+ return false unless valid_position? position
80
+ case axis
81
+ when :x then @pos_x = position
82
+ when :y then @pos_y = position
83
+ end
84
+ true
85
+ end
86
+
87
+ def change_position(axis, value)
88
+ # Alter the bot's position by given value on given axis
89
+ new_position = if axis == :x
90
+ @pos_x + value
91
+ else
92
+ @pos_y + value
93
+ end
94
+ set_position(axis, new_position)
95
+ end
89
96
  end
90
97
  end
@@ -10,15 +10,20 @@ module Lemmibot
10
10
  loop do
11
11
  command = gets
12
12
  return unless command
13
- process_command(command.chomp)
13
+ begin
14
+ process_command(command.chomp)
15
+ rescue
16
+ # Malformed and failed commands should be ignored
17
+ end
14
18
  end
15
19
  end
16
20
 
21
+ private
22
+
17
23
  def process_command(command)
24
+ # Process a command string
18
25
  case command.upcase
19
- when /PLACE/
20
- args = place_arguments(command)
21
- @bot.place(args[:x], args[:y], args[:dir])
26
+ when /PLACE/ then place(command)
22
27
  when /MOVE/ then @bot.move
23
28
  when /LEFT/ then @bot.turn(:left)
24
29
  when /RIGHT/ then @bot.turn(:right)
@@ -26,8 +31,8 @@ module Lemmibot
26
31
  end
27
32
  end
28
33
 
29
- # Parses arguments for a PLACE command and returns them as a hash
30
34
  def place_arguments(command)
35
+ # Parse arguments for a PLACE command and return them as a hash
31
36
  params_string = command.split(' ')[1]
32
37
  params = params_string.split(',')
33
38
  {
@@ -37,10 +42,16 @@ module Lemmibot
37
42
  }
38
43
  end
39
44
 
40
- # Outputs a report of the bot's current position and direction
45
+ def place(command)
46
+ args = place_arguments(command)
47
+ @bot.place(args[:x], args[:y], args[:dir])
48
+ end
49
+
41
50
  def report
42
- return unless @bot.placed
43
- puts "#{@bot.pos_x},#{@bot.pos_y},#{@bot.direction.upcase}"
51
+ # Output a report of the bot's current position and direction
52
+ report = @bot.report
53
+ return unless report
54
+ puts "#{report[:x]},#{report[:y]},#{report[:dir].upcase}"
44
55
  end
45
56
  end
46
57
  end
@@ -1,3 +1,3 @@
1
1
  module Lemmibot
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lemmibot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Effy Elden
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: '0'
122
+ version: 2.0.0
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - ">="