maux_robot 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/maux_robot/formatter/csv.rb +10 -0
- data/lib/maux_robot/formatter/json.rb +12 -0
- data/lib/maux_robot/formatter.rb +13 -0
- data/lib/maux_robot/parser.rb +1 -1
- data/lib/maux_robot/position.rb +3 -2
- data/lib/maux_robot/robot.rb +1 -5
- data/lib/maux_robot/version.rb +1 -1
- data/lib/maux_robot.rb +3 -0
- data/spec/maux_robot/formatter/csv_spec.rb +11 -0
- data/spec/maux_robot/formatter/json_spec.rb +11 -0
- data/spec/maux_robot/formatter_spec.rb +21 -0
- data/spec/maux_robot/parser_spec.rb +2 -4
- data/spec/maux_robot/position_spec.rb +8 -9
- data/spec/maux_robot/robot_spec.rb +0 -2
- data/spec/maux_robot/table_spec.rb +0 -2
- data/spec/spec_helper.rb +3 -0
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcae61d13656d506d2d2b851f744ad89ab52019b
|
4
|
+
data.tar.gz: 55ccb6a55a0ecac20ed9a32ed4b4894e6396d928
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4bcf5f0d29bc5e2e06534f26d3ad31275829bb9f310c98a70fba8c6b2ee6081999c884c2a91fb5dee7bf8dbf8b2a33a1b04436319a64a21b9bb952bf8ff3b9e
|
7
|
+
data.tar.gz: c0e40e5920f39688a15e5018d7545fd6a81e6639791bd0394e182b2390b35198d68bd53089f180bd7aa990f390910d292f7f4554a33a64a3b10d2e7b71e3c9f4
|
data/lib/maux_robot/parser.rb
CHANGED
data/lib/maux_robot/position.rb
CHANGED
data/lib/maux_robot/robot.rb
CHANGED
@@ -9,7 +9,7 @@ module MauxRobot
|
|
9
9
|
attr_reader :position
|
10
10
|
|
11
11
|
extend Forwardable
|
12
|
-
def_delegators :@position, :left, :right
|
12
|
+
def_delegators :@position, :left, :right, :report
|
13
13
|
|
14
14
|
def initialize(table=MauxRobot::Table.new)
|
15
15
|
@table = table
|
@@ -31,9 +31,5 @@ module MauxRobot
|
|
31
31
|
@position = next_position
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
|
-
def report
|
36
|
-
puts @position if @position
|
37
|
-
end
|
38
34
|
end
|
39
35
|
end
|
data/lib/maux_robot/version.rb
CHANGED
data/lib/maux_robot.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe MauxRobot::Formatter::Csv do
|
4
|
+
let (:position) {MauxRobot::Position.new(1,2,:west)}
|
5
|
+
|
6
|
+
context '#generate' do
|
7
|
+
it "Formats a position as CSV" do
|
8
|
+
expect(subject.generate(position)).to eq('1,2,WEST')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe MauxRobot::Formatter::Json do
|
4
|
+
let (:position) {MauxRobot::Position.new(1,2,:west)}
|
5
|
+
|
6
|
+
context '#generate' do
|
7
|
+
it "Formats a position as JSON" do
|
8
|
+
expect(subject.generate(position)).to eq('{"x":1,"y":2,"face":"WEST"}')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe MauxRobot::Formatter do
|
4
|
+
context "#from" do
|
5
|
+
describe "valid format_types" do
|
6
|
+
it "returns csv formatter" do
|
7
|
+
expect(subject.from(:csv).class).to eq(MauxRobot::Formatter::Csv)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns json formatter' do
|
11
|
+
expect(subject.from(:json).class).to eq(MauxRobot::Formatter::Json)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'invalid format_types' do
|
16
|
+
it 'defaults to csv formatter' do
|
17
|
+
expect(subject.from(:anything).class).to eq(MauxRobot::Formatter::Csv)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'maux_robot'
|
4
|
-
|
5
3
|
describe MauxRobot::Parser do
|
6
4
|
describe '#parse' do
|
7
5
|
context 'valid orders' do
|
@@ -10,11 +8,11 @@ describe MauxRobot::Parser do
|
|
10
8
|
end
|
11
9
|
|
12
10
|
it '#report csv' do
|
13
|
-
expect(subject.parse('REPORT CSV')).to eq(order: :report, arguments: {
|
11
|
+
expect(subject.parse('REPORT CSV')).to eq(order: :report, arguments: { format_type: :csv })
|
14
12
|
end
|
15
13
|
|
16
14
|
it '#report json' do
|
17
|
-
expect(subject.parse('REPORT JSON')).to eq(order: :report, arguments: {
|
15
|
+
expect(subject.parse('REPORT JSON')).to eq(order: :report, arguments: { format_type: :json })
|
18
16
|
end
|
19
17
|
|
20
18
|
it '#move' do
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'maux_robot'
|
4
|
-
|
5
3
|
describe MauxRobot::Position do
|
6
4
|
describe '#initialize' do
|
7
5
|
context 'given text input' do
|
@@ -119,25 +117,26 @@ describe MauxRobot::Position do
|
|
119
117
|
end
|
120
118
|
end
|
121
119
|
|
122
|
-
describe '#
|
120
|
+
describe '#report' do
|
123
121
|
context 'if x, y and face are defined' do
|
124
122
|
let(:position) { MauxRobot::Position.new(5, 0, :north) }
|
125
|
-
|
126
|
-
|
123
|
+
|
124
|
+
it 'prints X,Y,FACE' do
|
125
|
+
expect { position.report }.to output("5,0,NORTH\n").to_stdout
|
127
126
|
end
|
128
127
|
end
|
129
128
|
|
130
129
|
context 'if only face is defined' do
|
131
130
|
let(:position) { MauxRobot::Position.new(nil, nil, 'SOUTH') }
|
132
|
-
it '
|
133
|
-
expect
|
131
|
+
it 'prints 0,0,FACE' do
|
132
|
+
expect { position.report }.to output("0,0,SOUTH\n").to_stdout
|
134
133
|
end
|
135
134
|
end
|
136
135
|
|
137
136
|
context 'if face is not defined' do
|
138
137
|
let(:position) { MauxRobot::Position.new(5, 0, nil) }
|
139
|
-
it '
|
140
|
-
expect
|
138
|
+
it 'prints X,Y,INVALID' do
|
139
|
+
expect { position.report }.to output("5,0,INVALID\n").to_stdout
|
141
140
|
end
|
142
141
|
end
|
143
142
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maux_robot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mauricio Vieira
|
@@ -44,16 +44,23 @@ files:
|
|
44
44
|
- bin/maux_robot
|
45
45
|
- lib/maux_robot.rb
|
46
46
|
- lib/maux_robot/cli.rb
|
47
|
+
- lib/maux_robot/formatter.rb
|
48
|
+
- lib/maux_robot/formatter/csv.rb
|
49
|
+
- lib/maux_robot/formatter/json.rb
|
47
50
|
- lib/maux_robot/parser.rb
|
48
51
|
- lib/maux_robot/position.rb
|
49
52
|
- lib/maux_robot/robot.rb
|
50
53
|
- lib/maux_robot/table.rb
|
51
54
|
- lib/maux_robot/version.rb
|
52
55
|
- spec/maux_robot/cli_spec.rb
|
56
|
+
- spec/maux_robot/formatter/csv_spec.rb
|
57
|
+
- spec/maux_robot/formatter/json_spec.rb
|
58
|
+
- spec/maux_robot/formatter_spec.rb
|
53
59
|
- spec/maux_robot/parser_spec.rb
|
54
60
|
- spec/maux_robot/position_spec.rb
|
55
61
|
- spec/maux_robot/robot_spec.rb
|
56
62
|
- spec/maux_robot/table_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
57
64
|
homepage: https://github.com/mauriciovieira/maux_robot
|
58
65
|
licenses:
|
59
66
|
- GPL-3.0
|