savage 0.1.0 → 0.2.0
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.
- data/VERSION +1 -1
- data/lib/savage/direction_proxy.rb +18 -0
- data/lib/savage/directions/arc_to.rb +4 -5
- data/lib/savage/directions/close_path.rb +5 -1
- data/lib/savage/directions/coordinate_target.rb +0 -3
- data/lib/savage/directions/cubic_curve_to.rb +22 -11
- data/lib/savage/directions/horizontal_to.rb +3 -4
- data/lib/savage/directions/line_to.rb +3 -4
- data/lib/savage/directions/move_to.rb +3 -4
- data/lib/savage/directions/point_target.rb +0 -3
- data/lib/savage/directions/quadratic_curve_to.rb +22 -11
- data/lib/savage/directions/vertical_to.rb +3 -4
- data/lib/savage/parser.rb +139 -0
- data/lib/savage/path.rb +33 -4
- data/lib/savage/sub_path.rb +29 -29
- data/lib/savage/utils.rb +6 -0
- data/lib/savage.rb +2 -2
- data/savage.gemspec +5 -2
- data/spec/savage/directions/cubic_curve_to_spec.rb +81 -53
- data/spec/savage/directions/quadratic_curve_spec.rb +83 -41
- data/spec/savage/parser_spec.rb +174 -0
- data/spec/savage/path_spec.rb +88 -7
- data/spec/savage/sub_path_spec.rb +73 -30
- data/spec/shared/direction.rb +13 -5
- metadata +6 -3
- data/lib/savage/core_extensions/string.rb +0 -8
@@ -3,8 +3,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
include Savage
|
4
4
|
|
5
5
|
describe SubPath do
|
6
|
-
it 'should have a
|
7
|
-
SubPath.new.respond_to?(:
|
6
|
+
it 'should have a directions list' do
|
7
|
+
SubPath.new.respond_to?(:directions).should == true
|
8
8
|
end
|
9
9
|
it 'should have a move_to method' do
|
10
10
|
SubPath.new.respond_to?(:move_to).should == true
|
@@ -36,15 +36,43 @@ describe SubPath do
|
|
36
36
|
it 'should have a to_command method' do
|
37
37
|
SubPath.new.respond_to?(:to_command).should == true
|
38
38
|
end
|
39
|
+
it 'should be able to be constructed empty' do
|
40
|
+
lambda { SubPath.new }.should_not raise_error
|
41
|
+
end
|
42
|
+
it 'should be able to be constructed with a starting point (absolute move to)' do
|
43
|
+
path = SubPath.new(100,200)
|
44
|
+
path.directions.length.should == 1
|
45
|
+
path.directions.last.class.should == Directions::MoveTo
|
46
|
+
end
|
47
|
+
it 'should be able to build itself in a block' do
|
48
|
+
path = SubPath.new(100,200) do |p|
|
49
|
+
p.line_to 300, 400
|
50
|
+
p.cubic_curve_to 500,600,700,800,900,1000
|
51
|
+
p.arc_to 100,200,123,1,1,300,400
|
52
|
+
end
|
53
|
+
path.directions[0].class.should == Directions::MoveTo
|
54
|
+
path.directions[1].class.should == Directions::LineTo
|
55
|
+
path.directions[2].class.should == Directions::CubicCurveTo
|
56
|
+
path.directions[3].class.should == Directions::ArcTo
|
57
|
+
|
58
|
+
path2 = SubPath.new do |p|
|
59
|
+
p.line_to 300, 400
|
60
|
+
p.cubic_curve_to 500,600,700,800,900,1000
|
61
|
+
p.arc_to 100,200,123,1,1,300,400
|
62
|
+
end
|
63
|
+
path2.directions[0].class.should == Directions::LineTo
|
64
|
+
path2.directions[1].class.should == Directions::CubicCurveTo
|
65
|
+
path2.directions[2].class.should == Directions::ArcTo
|
66
|
+
end
|
39
67
|
describe '#closed?' do
|
40
|
-
it 'should be true if the last direction in the
|
68
|
+
it 'should be true if the last direction in the directions list is of type ClosePath' do
|
41
69
|
path = SubPath.new
|
42
70
|
path.move_to 100, 300
|
43
71
|
path.line_to 243, 21
|
44
72
|
path.close_path
|
45
73
|
path.closed?.should == true
|
46
74
|
end
|
47
|
-
it 'should be false if the last direction in the
|
75
|
+
it 'should be false if the last direction in the directions list is of any other type or absent' do
|
48
76
|
path = SubPath.new
|
49
77
|
path.move_to 100, 300
|
50
78
|
path.line_to 234, 21
|
@@ -54,39 +82,54 @@ describe SubPath do
|
|
54
82
|
end
|
55
83
|
end
|
56
84
|
describe '#to_command' do
|
57
|
-
|
58
|
-
path = SubPath.new
|
59
|
-
path.move_to 100, 200
|
60
|
-
|
61
|
-
|
62
|
-
path.
|
63
|
-
path.
|
64
|
-
|
85
|
+
before :each do
|
86
|
+
@path = SubPath.new
|
87
|
+
@dir_1 = @path.move_to 100, 200
|
88
|
+
end
|
89
|
+
it 'should output the concatenation of all the subdirections if no two are the same in sequence' do
|
90
|
+
dir_2 = @path.horizontal_to -200
|
91
|
+
dir_3 = @path.quadratic_curve_to 342, -341.23, 405, 223
|
92
|
+
dir_4 = @path.line_to -342.002, 231.42
|
93
|
+
dir_5 = @path.close_path
|
94
|
+
@path.to_command.should == @dir_1.to_command << dir_2.to_command << dir_3.to_command << dir_4.to_command << dir_5.to_command
|
65
95
|
end
|
66
96
|
it 'should strip the command code if the previous code was the same as the present' do
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
com4 = path.line_to -234, 502
|
72
|
-
path.to_command.should == 'M100 200H-200L-342.002 231.42-234 502'
|
97
|
+
dir_2 = @path.horizontal_to -200
|
98
|
+
dir_3 = @path.line_to -342.002, 231.42
|
99
|
+
dir_4 = @path.line_to -234, 502
|
100
|
+
@path.to_command.should == @dir_1.to_command << dir_2.to_command << dir_3.to_command << dir_4.to_command[1..-1]
|
73
101
|
end
|
74
|
-
it 'should strip the command code if the previous code was
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
102
|
+
it 'should not strip the command code if the previous code was the same as the present, but of different absoluteness' do
|
103
|
+
dir_2 = @path.horizontal_to -200
|
104
|
+
dir_3 = @path.line_to -342.002, 231.42
|
105
|
+
dir_4 = @path.line_to -234, 502, false
|
106
|
+
@path.to_command.should == @dir_1.to_command << dir_2.to_command << dir_3.to_command << dir_4.to_command
|
107
|
+
end
|
108
|
+
it 'should strip the command code if the previous code was a MoveTo and the current code is an absolute LineTo' do
|
109
|
+
dir_2 = @path.line_to -342.002, 231.42
|
110
|
+
dir_3 = @path.line_to -234, 502
|
111
|
+
@path.to_command.should == @dir_1.to_command << dir_2.to_command[1..-1] << dir_3.to_command[1..-1]
|
112
|
+
end
|
113
|
+
it 'should not strip the command code if the previous code was a MoveTo and the current code is a relative LineTo' do
|
114
|
+
dir_2 = @path.line_to -342.002, 231.42, false
|
115
|
+
dir_3 = @path.line_to -234, 502
|
116
|
+
@path.to_command.should == @dir_1.to_command << dir_2.to_command << dir_3.to_command
|
117
|
+
end
|
118
|
+
it 'should add leading whitespace if the first coordinate of the code-stripped direction is not negative' do
|
119
|
+
dir_2 = @path.horizontal_to -200
|
120
|
+
dir_3 = @path.line_to -342.002, 231.42
|
121
|
+
dir_4 = @path.line_to 234, 502
|
122
|
+
@path.to_command.should == @dir_1.to_command << dir_2.to_command << dir_3.to_command << dir_4.to_command[1..-1].insert(0,' ')
|
80
123
|
end
|
81
124
|
end
|
82
|
-
describe 'move_to' do
|
125
|
+
describe '#move_to' do
|
83
126
|
before :each do
|
84
127
|
@path = SubPath.new
|
85
128
|
end
|
86
129
|
context 'when the command list is empty' do
|
87
|
-
it 'should add a MoveTo command on to the
|
130
|
+
it 'should add a MoveTo command on to the directions list' do
|
88
131
|
this_move = @path.move_to(100,200)
|
89
|
-
@path.
|
132
|
+
@path.directions.should == [this_move]
|
90
133
|
end
|
91
134
|
it 'should return the newly created MoveTo command' do
|
92
135
|
@path.move_to(100,200).class.should == Directions::MoveTo
|
@@ -96,7 +139,7 @@ describe SubPath do
|
|
96
139
|
it 'does something' do
|
97
140
|
first_move = @path.move_to(200,400)
|
98
141
|
@path.move_to(100,200)
|
99
|
-
@path.
|
142
|
+
@path.directions.should == [first_move]
|
100
143
|
end
|
101
144
|
it 'should return nil' do
|
102
145
|
@path.move_to(200,400)
|
@@ -104,9 +147,9 @@ describe SubPath do
|
|
104
147
|
end
|
105
148
|
end
|
106
149
|
end
|
107
|
-
describe '#
|
150
|
+
describe '#directions' do
|
108
151
|
it 'should be able to access items via the bracket operator' do
|
109
|
-
SubPath.new.
|
152
|
+
SubPath.new.directions.respond_to?(:[]).should == true
|
110
153
|
end
|
111
154
|
end
|
112
155
|
end
|
data/spec/shared/direction.rb
CHANGED
@@ -6,16 +6,24 @@ share_as :DirectionShared do
|
|
6
6
|
it 'should have an absolute? method' do
|
7
7
|
@dir.respond_to?(:absolute?).should == true
|
8
8
|
end
|
9
|
+
it 'should have a command_code method' do
|
10
|
+
@dir.respond_to?(:command_code).should == true
|
11
|
+
end
|
9
12
|
describe '#to_command' do
|
13
|
+
it "should start with the command\'s command code" do
|
14
|
+
@dir.to_command[0,1].should == @dir.command_code
|
15
|
+
end
|
16
|
+
it 'should only have one alphabetical command code' do
|
17
|
+
@dir.to_command.match(/[A-Za-z]/).size.should == 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
describe '#command_code' do
|
10
21
|
it 'should start with a lower-case letter when not absolute' do
|
11
22
|
rel_dir = create_relative
|
12
|
-
|
23
|
+
rel_dir.command_code.should == command_code.downcase
|
13
24
|
end
|
14
25
|
it 'should start with a capital letter when absolute' do
|
15
|
-
|
16
|
-
end
|
17
|
-
it 'should only have one alphabetical command code' do
|
18
|
-
@dir.to_command.match(/[A-Za-z]/).size.should == 1
|
26
|
+
@dir.command_code.should == command_code.upcase
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jeremy Holland
|
@@ -48,8 +48,8 @@ files:
|
|
48
48
|
- Rakefile
|
49
49
|
- VERSION
|
50
50
|
- lib/savage.rb
|
51
|
-
- lib/savage/core_extensions/string.rb
|
52
51
|
- lib/savage/direction.rb
|
52
|
+
- lib/savage/direction_proxy.rb
|
53
53
|
- lib/savage/directions/arc_to.rb
|
54
54
|
- lib/savage/directions/close_path.rb
|
55
55
|
- lib/savage/directions/coordinate_target.rb
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/savage/directions/point_target.rb
|
61
61
|
- lib/savage/directions/quadratic_curve_to.rb
|
62
62
|
- lib/savage/directions/vertical_to.rb
|
63
|
+
- lib/savage/parser.rb
|
63
64
|
- lib/savage/path.rb
|
64
65
|
- lib/savage/sub_path.rb
|
65
66
|
- lib/savage/utils.rb
|
@@ -73,6 +74,7 @@ files:
|
|
73
74
|
- spec/savage/directions/point_spec.rb
|
74
75
|
- spec/savage/directions/quadratic_curve_spec.rb
|
75
76
|
- spec/savage/directions/vertical_to_spec.rb
|
77
|
+
- spec/savage/parser_spec.rb
|
76
78
|
- spec/savage/path_spec.rb
|
77
79
|
- spec/savage/sub_path_spec.rb
|
78
80
|
- spec/savage_spec.rb
|
@@ -122,6 +124,7 @@ test_files:
|
|
122
124
|
- spec/savage/directions/point_spec.rb
|
123
125
|
- spec/savage/directions/quadratic_curve_spec.rb
|
124
126
|
- spec/savage/directions/vertical_to_spec.rb
|
127
|
+
- spec/savage/parser_spec.rb
|
125
128
|
- spec/savage/path_spec.rb
|
126
129
|
- spec/savage/sub_path_spec.rb
|
127
130
|
- spec/savage_spec.rb
|