savage 1.1.7 → 1.1.8
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/README.rdoc +1 -0
- data/VERSION +1 -1
- data/lib/savage/directions/arc_to.rb +3 -3
- data/lib/savage/parser.rb +32 -65
- data/savage.gemspec +2 -2
- data/spec/savage/directions/arc_to_spec.rb +1 -1
- data/spec/savage/directions/close_path_spec.rb +1 -1
- data/spec/savage/directions/cubic_curve_to_spec.rb +1 -1
- data/spec/savage/directions/horizontal_to_spec.rb +1 -1
- data/spec/savage/directions/line_to_spec.rb +1 -1
- data/spec/savage/directions/move_to_spec.rb +1 -1
- data/spec/savage/directions/quadratic_curve_spec.rb +1 -1
- data/spec/savage/directions/vertical_to_spec.rb +1 -1
- data/spec/shared/coordinate_target.rb +2 -2
- data/spec/shared/direction.rb +1 -1
- data/spec/shared/point_target.rb +2 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -93,6 +93,7 @@ I have no doubt that will be some problems with this thing, as well as features
|
|
93
93
|
* Jeremy Holland (jeremy@jeremypholland.com, github:awebneck) -- author
|
94
94
|
* Christoffer Klang (toffeklang@yahoo.se, github:christoffer) -- regexp improvements
|
95
95
|
* MatmaRex (github:MatmaRex) -- parser improvements, scientific notation support, bug fixes
|
96
|
+
* Brandon Liu (github:bdon) -- spec improvements
|
96
97
|
|
97
98
|
== Copyright
|
98
99
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.8
|
@@ -7,8 +7,8 @@ module Savage
|
|
7
7
|
super(target_x, target_y, absolute)
|
8
8
|
@radius = Point.new(radius_x, radius_y)
|
9
9
|
@rotation = rotation
|
10
|
-
@large_arc = large_arc
|
11
|
-
@sweep = sweep
|
10
|
+
@large_arc = large_arc.is_a?(Numeric) ? large_arc > 0 : large_arc
|
11
|
+
@sweep = sweep.is_a?(Numeric) ? sweep > 0 : sweep
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_command
|
@@ -20,4 +20,4 @@ module Savage
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
data/lib/savage/parser.rb
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
module Savage
|
2
2
|
class Parser
|
3
|
+
DIRECTIONS = {
|
4
|
+
:m => {:class => Directions::MoveTo,
|
5
|
+
:args => 2},
|
6
|
+
:l => {:class => Directions::LineTo,
|
7
|
+
:args => 2},
|
8
|
+
:h => {:class => Directions::HorizontalTo,
|
9
|
+
:args => 1},
|
10
|
+
:v => {:class => Directions::VerticalTo,
|
11
|
+
:args => 1},
|
12
|
+
:c => {:class => Directions::CubicCurveTo,
|
13
|
+
:args => 6},
|
14
|
+
:s => {:class => Directions::CubicCurveTo,
|
15
|
+
:args => 4},
|
16
|
+
:q => {:class => Directions::QuadraticCurveTo,
|
17
|
+
:args => 4},
|
18
|
+
:t => {:class => Directions::QuadraticCurveTo,
|
19
|
+
:args => 2},
|
20
|
+
:a => {:class => Directions::ArcTo,
|
21
|
+
:args => 7}
|
22
|
+
}
|
23
|
+
|
3
24
|
class << self
|
4
25
|
def parse(parsable)
|
5
26
|
raise TypeError if parsable.class != String
|
@@ -50,84 +71,30 @@ module Savage
|
|
50
71
|
|
51
72
|
def build_direction(parsable, force_absolute=false)
|
52
73
|
directions = []
|
53
|
-
coordinates = extract_coordinates parsable
|
74
|
+
@coordinates = extract_coordinates parsable
|
54
75
|
recurse_code = parsable[0,1]
|
55
76
|
first_absolute = force_absolute
|
56
77
|
|
57
78
|
# we need to handle this separately, since ClosePath doesn't take any coordinates
|
58
|
-
if coordinates.empty? && recurse_code =~ /[Zz]/
|
79
|
+
if @coordinates.empty? && recurse_code =~ /[Zz]/
|
59
80
|
directions << Directions::ClosePath.new(parsable[0,1] == parsable[0,1].upcase)
|
60
81
|
end
|
61
82
|
|
62
|
-
until coordinates.empty?
|
83
|
+
until @coordinates.empty?
|
63
84
|
absolute = (first_absolute || parsable[0,1] == parsable[0,1].upcase)
|
64
|
-
|
65
|
-
|
66
|
-
x = coordinates.shift
|
67
|
-
y = coordinates.shift
|
68
|
-
raise TypeError if x.nil? || y.nil?
|
69
|
-
directions << Directions::MoveTo.new(x,y,absolute)
|
70
|
-
recurse_code = 'L'
|
71
|
-
when /[Ll]/
|
72
|
-
x = coordinates.shift
|
73
|
-
y = coordinates.shift
|
74
|
-
raise TypeError if x.nil? || y.nil?
|
75
|
-
directions << Directions::LineTo.new(x,y,absolute)
|
76
|
-
when /[Hh]/
|
77
|
-
target = coordinates.shift
|
78
|
-
raise TypeError if target.nil?
|
79
|
-
directions << Directions::HorizontalTo.new(target,absolute)
|
80
|
-
when /[Vv]/
|
81
|
-
target = coordinates.shift
|
82
|
-
raise TypeError if target.nil?
|
83
|
-
directions << Directions::VerticalTo.new(target,absolute)
|
84
|
-
when /[Cc]/
|
85
|
-
control_1_x = coordinates.shift
|
86
|
-
control_1_y = coordinates.shift
|
87
|
-
control_2_x = coordinates.shift
|
88
|
-
control_2_y = coordinates.shift
|
89
|
-
x = coordinates.shift
|
90
|
-
y = coordinates.shift
|
91
|
-
raise TypeError if x.nil? || y.nil? || control_1_x.nil? || control_1_y.nil? || control_2_x.nil? || control_2_y.nil?
|
92
|
-
directions << Directions::CubicCurveTo.new(control_1_x,control_1_y,control_2_x,control_2_y,x,y,absolute)
|
93
|
-
when /[Ss]/
|
94
|
-
control_2_x = coordinates.shift
|
95
|
-
control_2_y = coordinates.shift
|
96
|
-
x = coordinates.shift
|
97
|
-
y = coordinates.shift
|
98
|
-
raise TypeError if x.nil? || y.nil? || control_2_x.nil? || control_2_y.nil?
|
99
|
-
directions << Directions::CubicCurveTo.new(control_2_x,control_2_y,x,y,absolute)
|
100
|
-
when /[Qq]/
|
101
|
-
control_x = coordinates.shift
|
102
|
-
control_y = coordinates.shift
|
103
|
-
x = coordinates.shift
|
104
|
-
y = coordinates.shift
|
105
|
-
raise TypeError if x.nil? || y.nil? || control_x.nil? || control_y.nil?
|
106
|
-
directions << Directions::QuadraticCurveTo.new(control_x,control_y,x,y,absolute)
|
107
|
-
when /[Tt]/
|
108
|
-
x = coordinates.shift
|
109
|
-
y = coordinates.shift
|
110
|
-
raise TypeError if x.nil? || y.nil?
|
111
|
-
directions << Directions::QuadraticCurveTo.new(x,y,absolute)
|
112
|
-
when /[Aa]/
|
113
|
-
rx = coordinates.shift
|
114
|
-
ry = coordinates.shift
|
115
|
-
rotation = coordinates.shift
|
116
|
-
large_arc = (coordinates.shift > 0) ? true : false
|
117
|
-
sweep = (coordinates.shift > 0) ? true : false
|
118
|
-
x = coordinates.shift
|
119
|
-
y = coordinates.shift
|
120
|
-
raise TypeError if x.nil? || y.nil? || rx.nil? || ry.nil? || rotation.nil?
|
121
|
-
directions << Directions::ArcTo.new(rx,ry,rotation,large_arc,sweep,x,y,absolute)
|
122
|
-
when /[^MmLlHhVvCcSsQqTtAaZz]/
|
123
|
-
coordinates = []
|
124
|
-
raise TypeError
|
125
|
-
end
|
85
|
+
directions << construct_direction(recurse_code.strip[0].downcase.intern, absolute)
|
86
|
+
recurse_code = 'L' if recurse_code.downcase =~ /m/
|
126
87
|
first_absolute = false
|
127
88
|
end
|
128
89
|
|
129
90
|
directions
|
130
91
|
end
|
92
|
+
|
93
|
+
def construct_direction(recurse_code, absolute)
|
94
|
+
args = @coordinates.shift DIRECTIONS[recurse_code][:args]
|
95
|
+
raise TypeError if args.any?(&:nil?)
|
96
|
+
DIRECTIONS[recurse_code][:class].new(*args, absolute)
|
97
|
+
end
|
131
98
|
|
132
99
|
def extract_coordinates(command_string)
|
133
100
|
coordinates = []
|
data/savage.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "savage"
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeremy Holland"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-01-03"
|
13
13
|
s.description = "A little gem for extracting and manipulating SVG vector path data."
|
14
14
|
s.email = "jeremy@jeremypholland.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -9,7 +9,7 @@ describe ClosePath do
|
|
9
9
|
def create_relative; ClosePath.new(false); end
|
10
10
|
def command_code; 'z'; end
|
11
11
|
include Command
|
12
|
-
|
12
|
+
it_behaves_like 'Direction'
|
13
13
|
it 'should be constructed with with either no parameters or a single boolean parameter' do
|
14
14
|
lambda { ClosePath.new }.should_not raise_error
|
15
15
|
lambda { ClosePath.new true }.should_not raise_error
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
shared_examples 'CoordinateTarget' do
|
2
2
|
before :each do
|
3
3
|
@dir = dir_class.new(100)
|
4
4
|
end
|
5
5
|
include Command
|
6
|
-
|
6
|
+
it_behaves_like 'Direction'
|
7
7
|
it 'should have an accessible target, based on the constructor argument' do
|
8
8
|
@dir.respond_to?(:target).should == true
|
9
9
|
@dir.target.should == 100
|
data/spec/shared/direction.rb
CHANGED
data/spec/shared/point_target.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
shared_examples_for 'PointTarget' do
|
2
2
|
before :each do
|
3
3
|
@dir = dir_class.new(100,200)
|
4
4
|
end
|
5
5
|
include Command
|
6
|
-
|
6
|
+
it_behaves_like 'Direction'
|
7
7
|
it 'should have a target' do
|
8
8
|
@dir.respond_to?(:target).should == true
|
9
9
|
@dir.target.class.should == Point
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: savage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|