vedeu 0.0.27 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/README.md +1 -0
- data/lib/vedeu/output/text_adaptor.rb +31 -0
- data/lib/vedeu/process/process.rb +8 -4
- data/lib/vedeu/support/parser.rb +30 -7
- data/lib/vedeu/support/parsing/hash_parser.rb +34 -0
- data/lib/vedeu/support/parsing/json_parser.rb +13 -0
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/output/text_adaptor_test.rb +60 -0
- data/test/lib/vedeu/process/process_test.rb +38 -35
- data/test/lib/vedeu/support/parser_test.rb +37 -5
- data/test/lib/vedeu/support/parsing/hash_parser_test.rb +45 -0
- data/test/lib/vedeu/support/parsing/json_parser_test.rb +35 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94dacb4855864e050d993abf5c15d94f6333635e
|
4
|
+
data.tar.gz: 2fd4c3435718f164c6629482e64ee20fb74b4b82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ba8636d8fafa852231a6ea633353debd9d8a18476b145ab2d26122590d8984f4b4107ec1ac9bad4de0102d67a61eb8423acda8611d650a6aabd1db4a3ebee20
|
7
|
+
data.tar.gz: e9a3952b9df0521f4eb21cc457da2c2cfd4d3fe8e1c143ba32f1d2ec07505a0f6d647a2e0a5a576e20deecdd3a788903126b035067bec848c55b98db1616b392
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../models/line'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
class TextAdaptor
|
5
|
+
def self.adapt(text)
|
6
|
+
new(text).adapt
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(text)
|
10
|
+
@text = text
|
11
|
+
end
|
12
|
+
|
13
|
+
def adapt
|
14
|
+
return [] if no_content?
|
15
|
+
|
16
|
+
lines.map { |line| Line.new({ streams: { text: line } }) }
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :text
|
22
|
+
|
23
|
+
def lines
|
24
|
+
text.split(/\n/)
|
25
|
+
end
|
26
|
+
|
27
|
+
def no_content?
|
28
|
+
text.nil? || text.empty?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -11,17 +11,21 @@ module Vedeu
|
|
11
11
|
def initialize; end
|
12
12
|
|
13
13
|
def evaluate
|
14
|
-
|
14
|
+
return false if input.nil? || input.empty?
|
15
15
|
|
16
|
-
|
16
|
+
fail StopIteration if stop_requested?
|
17
17
|
|
18
|
-
|
18
|
+
Parser.parse(result) unless no_result?
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
+
def stop_requested?
|
24
|
+
result == :stop
|
25
|
+
end
|
26
|
+
|
23
27
|
def no_result?
|
24
|
-
result.nil? || result.empty?
|
28
|
+
result.nil? || result.empty?
|
25
29
|
end
|
26
30
|
|
27
31
|
def result
|
data/lib/vedeu/support/parser.rb
CHANGED
@@ -1,27 +1,50 @@
|
|
1
|
-
require 'oj'
|
2
|
-
|
3
1
|
require_relative '../models/composition'
|
2
|
+
require_relative 'parsing/hash_parser'
|
3
|
+
require_relative 'parsing/json_parser'
|
4
4
|
|
5
5
|
module Vedeu
|
6
|
+
class ParseError < StandardError; end
|
7
|
+
|
6
8
|
class Parser
|
7
9
|
def self.parse(output)
|
8
10
|
new(output).parse
|
9
11
|
end
|
10
12
|
|
11
|
-
def initialize(output)
|
12
|
-
@output = output
|
13
|
+
def initialize(output = {})
|
14
|
+
@output = output
|
13
15
|
end
|
14
16
|
|
15
17
|
def parse
|
16
|
-
|
18
|
+
return nil if empty?
|
19
|
+
|
20
|
+
Composition.new(parsed_output) #.enqueue
|
17
21
|
end
|
18
22
|
|
19
23
|
private
|
20
24
|
|
21
25
|
attr_reader :output
|
22
26
|
|
23
|
-
def
|
24
|
-
|
27
|
+
def parsed_output
|
28
|
+
@parsed ||= parser.parse(output)
|
29
|
+
end
|
30
|
+
|
31
|
+
def parser
|
32
|
+
return JSONParser if json?
|
33
|
+
return HashParser if hash?
|
34
|
+
|
35
|
+
fail ParseError, 'Cannot process output from command.'
|
36
|
+
end
|
37
|
+
|
38
|
+
def hash?
|
39
|
+
output.is_a?(Hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
def json?
|
43
|
+
output.is_a?(String)
|
44
|
+
end
|
45
|
+
|
46
|
+
def empty?
|
47
|
+
output.nil? || output.empty?
|
25
48
|
end
|
26
49
|
end
|
27
50
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative '../../output/text_adaptor'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
class HashParser
|
5
|
+
def self.parse(output = {})
|
6
|
+
new(output).parse
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(output = {})
|
10
|
+
@output = output
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse
|
14
|
+
{ interfaces: interfaces }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :output
|
20
|
+
|
21
|
+
def interfaces
|
22
|
+
stringified_keys.map do |name, content|
|
23
|
+
{
|
24
|
+
name: name,
|
25
|
+
lines: TextAdaptor.adapt(content)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def stringified_keys
|
31
|
+
output.inject({}) { |a, (k, v)| a[k.to_s] = v; a }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/vedeu/version.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative '../../../test_helper'
|
2
|
+
require_relative '../../../../lib/vedeu/output/text_adaptor'
|
3
|
+
|
4
|
+
module Vedeu
|
5
|
+
describe TextAdaptor do
|
6
|
+
let(:described_class) { TextAdaptor }
|
7
|
+
let(:text) { '' }
|
8
|
+
|
9
|
+
describe '#initialize' do
|
10
|
+
let(:subject) { described_class.new(text) }
|
11
|
+
|
12
|
+
it 'returns an TextAdaptor instance' do
|
13
|
+
subject.must_be_instance_of(TextAdaptor)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets an instance variable' do
|
17
|
+
subject.instance_variable_get('@text').must_equal(text)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.adapt' do
|
22
|
+
let(:subject) { described_class.adapt(text) }
|
23
|
+
|
24
|
+
it 'returns an Array' do
|
25
|
+
subject.must_be_instance_of(Array)
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when processing an empty string' do
|
29
|
+
let(:text) { '' }
|
30
|
+
|
31
|
+
it 'returns an empty collection' do
|
32
|
+
subject.must_be_empty
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when processing a single line' do
|
37
|
+
let(:text) { "This is a single line of text.\n" }
|
38
|
+
|
39
|
+
it 'returns a collection of Line objects' do
|
40
|
+
subject.first.must_be_instance_of(Line)
|
41
|
+
|
42
|
+
subject.size.must_equal(1)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when processing multiple lines' do
|
47
|
+
let(:text) {
|
48
|
+
"Lorem ipsum dolor sit amet,\nConseactetur adipiscing.\n" \
|
49
|
+
"Curabitur aliquet, turpis id dui.\n\nConditum elemum.\n"
|
50
|
+
}
|
51
|
+
|
52
|
+
it 'returns a collection of Line objects' do
|
53
|
+
subject.first.must_be_instance_of(Line)
|
54
|
+
|
55
|
+
subject.size.must_equal(5)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,66 +1,69 @@
|
|
1
1
|
require_relative '../../../test_helper'
|
2
2
|
require_relative '../../../../lib/vedeu/process/process'
|
3
|
-
require_relative '../../../../lib/vedeu/repository/interface_repository'
|
3
|
+
# require_relative '../../../../lib/vedeu/repository/interface_repository'
|
4
|
+
require_relative '../../../support/dummy_command'
|
5
|
+
require_relative '../../../../lib/vedeu/repository/command_repository'
|
4
6
|
|
5
7
|
module Vedeu
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
describe '#initialize' do
|
12
|
-
let(:subject) { described_class.new }
|
8
|
+
class QuitCommand
|
9
|
+
def self.dispatch(*args)
|
10
|
+
:stop
|
11
|
+
end
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
class TestCommand
|
15
|
+
def self.dispatch(*args)
|
16
|
+
:test
|
17
17
|
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe Process do
|
21
|
+
let(:described_class) { Process }
|
18
22
|
|
19
23
|
describe '.evaluate' do
|
20
24
|
let(:subject) { described_class.evaluate }
|
21
|
-
let(:command) { Command.new }
|
22
|
-
let(:json) { {} }
|
23
25
|
|
24
26
|
before do
|
25
|
-
|
26
|
-
name
|
27
|
-
|
28
|
-
|
27
|
+
CommandRepository.create({
|
28
|
+
'name' => 'quit',
|
29
|
+
entity: QuitCommand,
|
30
|
+
keypress: 'q'
|
31
|
+
})
|
32
|
+
CommandRepository.create({
|
33
|
+
name: 'test',
|
34
|
+
entity: TestCommand,
|
35
|
+
keypress: 't'
|
29
36
|
})
|
30
37
|
Queue.stubs(:dequeue).returns(input)
|
31
|
-
|
32
|
-
command.stubs(:execute).returns(result)
|
33
|
-
Parser.stubs(:parse).returns(json)
|
34
|
-
Composition.stubs(:enqueue).returns([])
|
38
|
+
Parser.stubs(:parse).returns(Composition.new)
|
35
39
|
end
|
36
40
|
|
37
41
|
after do
|
38
|
-
|
39
|
-
Queue.clear
|
42
|
+
CommandRepository.reset
|
40
43
|
end
|
41
44
|
|
42
45
|
context 'when there is no input' do
|
43
|
-
|
44
|
-
|
46
|
+
let(:input) { '' }
|
47
|
+
|
48
|
+
it 'returns a FalseClass' do
|
49
|
+
subject.must_be_instance_of(FalseClass)
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
48
53
|
context 'when there is input' do
|
49
|
-
|
54
|
+
context 'and the result is :stop' do
|
55
|
+
let(:input) { 'q' }
|
50
56
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
it 'returns an Array' do
|
55
|
-
subject.must_be_instance_of(Array)
|
57
|
+
it 'raises an exception' do
|
58
|
+
proc { subject }.must_raise(StopIteration)
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
59
|
-
context '
|
60
|
-
let(:
|
62
|
+
context 'and there is a result' do
|
63
|
+
let(:input) { 't' }
|
61
64
|
|
62
|
-
it '
|
63
|
-
|
65
|
+
it 'returns an Composition' do
|
66
|
+
subject.must_be_instance_of(Composition)
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
@@ -19,10 +19,10 @@ module Vedeu
|
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'when the instance variable is nil' do
|
22
|
-
let(:
|
22
|
+
let(:subject) { described_class.new }
|
23
23
|
|
24
|
-
it 'set
|
25
|
-
subject.instance_variable_get("@output").must_equal(
|
24
|
+
it 'set an instance variable' do
|
25
|
+
subject.instance_variable_get("@output").must_equal({})
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -30,8 +30,40 @@ module Vedeu
|
|
30
30
|
describe '#parse' do
|
31
31
|
let(:subject) { described_class.parse(output) }
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
context 'when the output is empty' do
|
34
|
+
let(:output) {}
|
35
|
+
|
36
|
+
it 'returns a NilClass' do
|
37
|
+
subject.must_be_instance_of(NilClass)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when the output is JSON' do
|
42
|
+
let(:output) { "{\"some\": \"JSON\"}" }
|
43
|
+
|
44
|
+
it 'returns a Composition' do
|
45
|
+
subject.must_be_instance_of(Composition)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when the output is a Hash' do
|
50
|
+
let(:output) {
|
51
|
+
{
|
52
|
+
dummy: 'Some text...'
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
it 'returns a Composition' do
|
57
|
+
subject.must_be_instance_of(Composition)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when the output is anything else' do
|
62
|
+
let(:output) { [:invalid] }
|
63
|
+
|
64
|
+
it 'raises an exception' do
|
65
|
+
proc { subject }.must_raise(ParseError)
|
66
|
+
end
|
35
67
|
end
|
36
68
|
end
|
37
69
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative '../../../../test_helper'
|
2
|
+
require_relative '../../../../../lib/vedeu/support/parsing/hash_parser'
|
3
|
+
|
4
|
+
module Vedeu
|
5
|
+
describe HashParser do
|
6
|
+
let(:described_module) { HashParser }
|
7
|
+
let(:output) { {} }
|
8
|
+
|
9
|
+
describe '.parse' do
|
10
|
+
let(:subject) { described_module.parse(output) }
|
11
|
+
let(:lines) { mock }
|
12
|
+
|
13
|
+
before { TextAdaptor.stubs(:adapt).returns(lines) }
|
14
|
+
|
15
|
+
it 'returns a Hash' do
|
16
|
+
subject.must_be_instance_of(Hash)
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when the output is content for a collection of interfaces' do
|
20
|
+
let(:output) {
|
21
|
+
{
|
22
|
+
test: 'Some content...',
|
23
|
+
dummy: 'More content...'
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
it 'returns a Hash' do
|
28
|
+
subject.must_equal({ interfaces: [{ name: 'test', lines: lines }, { name: 'dummy', lines: lines }] })
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when the output is content for a single interface' do
|
33
|
+
let(:output) {
|
34
|
+
{
|
35
|
+
dummy: 'Some content...'
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
it 'returns a Hash' do
|
40
|
+
subject.must_equal({ interfaces: [{ name: 'dummy', lines: lines }] })
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative '../../../../test_helper'
|
2
|
+
require_relative '../../../../../lib/vedeu/support/parsing/json_parser'
|
3
|
+
|
4
|
+
module Vedeu
|
5
|
+
describe JSONParser do
|
6
|
+
let(:described_module) { JSONParser }
|
7
|
+
let(:output) { "{}" }
|
8
|
+
|
9
|
+
describe '.parse' do
|
10
|
+
let(:subject) { described_module.parse(output) }
|
11
|
+
|
12
|
+
it 'returns a Hash' do
|
13
|
+
subject.must_be_instance_of(Hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when the JSON is valid' do
|
17
|
+
let(:output) { File.read('test/support/json/int1_lin1_str1.json')}
|
18
|
+
|
19
|
+
it 'returns a Hash' do
|
20
|
+
subject.must_be_instance_of(Hash)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when the JSON is invalid' do
|
25
|
+
let(:output) { "{}" }
|
26
|
+
|
27
|
+
before { Oj.stubs(:load).raises(Oj::ParseError) }
|
28
|
+
|
29
|
+
it 'returns a Hash' do
|
30
|
+
subject.must_be_instance_of(Hash)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vedeu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Laking
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -189,6 +189,7 @@ extra_rdoc_files: []
|
|
189
189
|
files:
|
190
190
|
- ".gitignore"
|
191
191
|
- ".ruby-version"
|
192
|
+
- ".travis.yml"
|
192
193
|
- Gemfile
|
193
194
|
- Guardfile
|
194
195
|
- LICENSE.txt
|
@@ -218,6 +219,7 @@ files:
|
|
218
219
|
- lib/vedeu/models/style_collection.rb
|
219
220
|
- lib/vedeu/output/interface_renderer.rb
|
220
221
|
- lib/vedeu/output/output.rb
|
222
|
+
- lib/vedeu/output/text_adaptor.rb
|
221
223
|
- lib/vedeu/process/process.rb
|
222
224
|
- lib/vedeu/repository/command_repository.rb
|
223
225
|
- lib/vedeu/repository/interface_repository.rb
|
@@ -229,6 +231,8 @@ files:
|
|
229
231
|
- lib/vedeu/support/exit.rb
|
230
232
|
- lib/vedeu/support/geometry.rb
|
231
233
|
- lib/vedeu/support/parser.rb
|
234
|
+
- lib/vedeu/support/parsing/hash_parser.rb
|
235
|
+
- lib/vedeu/support/parsing/json_parser.rb
|
232
236
|
- lib/vedeu/support/queue.rb
|
233
237
|
- lib/vedeu/support/terminal.rb
|
234
238
|
- lib/vedeu/support/translator.rb
|
@@ -254,6 +258,7 @@ files:
|
|
254
258
|
- test/lib/vedeu/models/style_collection_test.rb
|
255
259
|
- test/lib/vedeu/output/interface_renderer_test.rb
|
256
260
|
- test/lib/vedeu/output/output_test.rb
|
261
|
+
- test/lib/vedeu/output/text_adaptor_test.rb
|
257
262
|
- test/lib/vedeu/process/process_test.rb
|
258
263
|
- test/lib/vedeu/repository/command_repository_test.rb
|
259
264
|
- test/lib/vedeu/repository/interface_repository_test.rb
|
@@ -265,6 +270,8 @@ files:
|
|
265
270
|
- test/lib/vedeu/support/exit_test.rb
|
266
271
|
- test/lib/vedeu/support/geometry_test.rb
|
267
272
|
- test/lib/vedeu/support/parser_test.rb
|
273
|
+
- test/lib/vedeu/support/parsing/hash_parser_test.rb
|
274
|
+
- test/lib/vedeu/support/parsing/json_parser_test.rb
|
268
275
|
- test/lib/vedeu/support/queue_test.rb
|
269
276
|
- test/lib/vedeu/support/terminal_test.rb
|
270
277
|
- test/lib/vedeu/support/translator_test.rb
|
@@ -334,6 +341,7 @@ test_files:
|
|
334
341
|
- test/lib/vedeu/models/style_collection_test.rb
|
335
342
|
- test/lib/vedeu/output/interface_renderer_test.rb
|
336
343
|
- test/lib/vedeu/output/output_test.rb
|
344
|
+
- test/lib/vedeu/output/text_adaptor_test.rb
|
337
345
|
- test/lib/vedeu/process/process_test.rb
|
338
346
|
- test/lib/vedeu/repository/command_repository_test.rb
|
339
347
|
- test/lib/vedeu/repository/interface_repository_test.rb
|
@@ -345,6 +353,8 @@ test_files:
|
|
345
353
|
- test/lib/vedeu/support/exit_test.rb
|
346
354
|
- test/lib/vedeu/support/geometry_test.rb
|
347
355
|
- test/lib/vedeu/support/parser_test.rb
|
356
|
+
- test/lib/vedeu/support/parsing/hash_parser_test.rb
|
357
|
+
- test/lib/vedeu/support/parsing/json_parser_test.rb
|
348
358
|
- test/lib/vedeu/support/queue_test.rb
|
349
359
|
- test/lib/vedeu/support/terminal_test.rb
|
350
360
|
- test/lib/vedeu/support/translator_test.rb
|