savage 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +45 -0
  6. data/VERSION +1 -0
  7. data/lib/savage/core_extensions/string.rb +8 -0
  8. data/lib/savage/direction.rb +29 -0
  9. data/lib/savage/directions/arc_to.rb +24 -0
  10. data/lib/savage/directions/close_path.rb +14 -0
  11. data/lib/savage/directions/coordinate_target.rb +20 -0
  12. data/lib/savage/directions/cubic_curve_to.rb +25 -0
  13. data/lib/savage/directions/horizontal_to.rb +10 -0
  14. data/lib/savage/directions/line_to.rb +10 -0
  15. data/lib/savage/directions/move_to.rb +10 -0
  16. data/lib/savage/directions/point_target.rb +20 -0
  17. data/lib/savage/directions/quadratic_curve_to.rb +22 -0
  18. data/lib/savage/directions/vertical_to.rb +10 -0
  19. data/lib/savage/path.rb +16 -0
  20. data/lib/savage/sub_path.rb +47 -0
  21. data/lib/savage/utils.rb +7 -0
  22. data/lib/savage.rb +9 -0
  23. data/savage.gemspec +100 -0
  24. data/spec/savage/directions/arc_to_spec.rb +96 -0
  25. data/spec/savage/directions/close_path_spec.rb +29 -0
  26. data/spec/savage/directions/cubic_curve_to_spec.rb +117 -0
  27. data/spec/savage/directions/horizontal_to_spec.rb +10 -0
  28. data/spec/savage/directions/line_to_spec.rb +10 -0
  29. data/spec/savage/directions/move_to_spec.rb +10 -0
  30. data/spec/savage/directions/point_spec.rb +12 -0
  31. data/spec/savage/directions/quadratic_curve_spec.rb +80 -0
  32. data/spec/savage/directions/vertical_to_spec.rb +10 -0
  33. data/spec/savage/path_spec.rb +24 -0
  34. data/spec/savage/sub_path_spec.rb +112 -0
  35. data/spec/savage_spec.rb +5 -0
  36. data/spec/shared/command.rb +13 -0
  37. data/spec/shared/coordinate_target.rb +35 -0
  38. data/spec/shared/direction.rb +21 -0
  39. data/spec/shared/point_target.rb +44 -0
  40. data/spec/spec.opts +1 -0
  41. data/spec/spec_helper.rb +36 -0
  42. metadata +132 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jeremy Holland
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = Savage
2
+
3
+ A little gem for extracting and manipulating SVG vector path data.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add specs for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Jeremy Holland. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "savage"
8
+ gem.summary = %Q{A little library to manipulate SVG path data}
9
+ gem.description = %Q{A little gem for extracting and manipulating SVG vector path data.}
10
+ gem.email = "jeremy@jeremypholland.com"
11
+ gem.homepage = "http://github.com/therubyneck/savage"
12
+ gem.authors = ["Jeremy Holland"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "savage #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,8 @@
1
+ class String
2
+ def constantize
3
+ unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
4
+ raise NameError, "#{self.inspect} is not a valid constant name!"
5
+ end
6
+ Object.module_eval("::#{$1}", __FILE__, __LINE__)
7
+ end
8
+ end
@@ -0,0 +1,29 @@
1
+ module Savage
2
+ module Directions
3
+ Point = Struct.new :x, :y
4
+ end
5
+
6
+ class Direction
7
+
8
+ include Utils
9
+
10
+ def initialize(absolute)
11
+ @absolute = absolute
12
+ end
13
+
14
+ def absolute?
15
+ @absolute
16
+ end
17
+ end
18
+ end
19
+
20
+ require File.dirname(__FILE__) + "/directions/close_path"
21
+ require File.dirname(__FILE__) + "/directions/coordinate_target"
22
+ require File.dirname(__FILE__) + "/directions/horizontal_to"
23
+ require File.dirname(__FILE__) + "/directions/vertical_to"
24
+ require File.dirname(__FILE__) + "/directions/point_target"
25
+ require File.dirname(__FILE__) + "/directions/move_to"
26
+ require File.dirname(__FILE__) + "/directions/line_to"
27
+ require File.dirname(__FILE__) + "/directions/quadratic_curve_to"
28
+ require File.dirname(__FILE__) + "/directions/cubic_curve_to"
29
+ require File.dirname(__FILE__) + "/directions/arc_to"
@@ -0,0 +1,24 @@
1
+ module Savage
2
+ module Directions
3
+ class ArcTo < PointTarget
4
+ attr_accessor :radius, :rotation, :large_arc, :sweep
5
+
6
+ def initialize(radius_x, radius_y, rotation, large_arc, sweep, target_x, target_y, absolute=true)
7
+ super(target_x, target_y, absolute)
8
+ @radius = Point.new(radius_x, radius_y)
9
+ @rotation = rotation
10
+ @large_arc = large_arc
11
+ @sweep = sweep
12
+ end
13
+
14
+ def to_command
15
+ command_code << "#{@radius.x} #{@radius.y} #{@rotation} #{bool_to_int(@large_arc)} #{bool_to_int(@sweep)} #{target.x} #{target.y}".gsub(/ -/,'-')
16
+ end
17
+
18
+ private
19
+ def command_code
20
+ (absolute?) ? 'A' : 'a'
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ module Savage
2
+ module Directions
3
+ class ClosePath < Direction
4
+
5
+ def initialize(absolute=true)
6
+ super(absolute)
7
+ end
8
+
9
+ def to_command
10
+ command_string = (absolute?) ? 'Z' : 'z'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ module Savage
2
+ module Directions
3
+ class CoordinateTarget < Direction
4
+
5
+ attr_accessor :target
6
+
7
+ def initialize(target, absolute=true)
8
+ @target = target
9
+ super(absolute)
10
+ end
11
+
12
+ def to_command
13
+ command_code << @target.to_s
14
+ end
15
+
16
+ private
17
+ def command_code; ''; end;
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ module Savage
2
+ module Directions
3
+ class CubicCurveTo < QuadraticCurveTo
4
+ attr_accessor :control_1
5
+
6
+ def initialize(control_1_x, control_1_y, control_2_x, control_2_y, target_x, target_y, absolute=true)
7
+ @control_1 = Point.new(control_1_x, control_1_y)
8
+ super(control_2_x, control_2_y, target_x, target_y, absolute)
9
+ end
10
+
11
+ def to_command(continuous=false)
12
+ command_code(continuous) << ((!continuous) ? "#{@control_1.x} #{@control_1.y} #{@control.x} #{@control.y} #{@target.x} #{@target.y}".gsub(/ -/,'-') : super().gsub(/[A-Za-z]/,''))
13
+ end
14
+
15
+ def control_2; @control; end
16
+ def control_2=(value); @control = value; end
17
+
18
+ private
19
+ def command_code(continuous=false)
20
+ return (absolute?) ? 'C' : 'c' unless continuous
21
+ (absolute?) ? 'S' : 's'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ module Savage
2
+ module Directions
3
+ class HorizontalTo < CoordinateTarget
4
+ private
5
+ def command_code
6
+ (absolute?) ? 'H' : 'h'
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Savage
2
+ module Directions
3
+ class LineTo < PointTarget
4
+ private
5
+ def command_code
6
+ (absolute?) ? 'L' : 'l'
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Savage
2
+ module Directions
3
+ class MoveTo < PointTarget
4
+ private
5
+ def command_code
6
+ (absolute?) ? 'M' : 'm'
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module Savage
2
+ module Directions
3
+ class PointTarget < Direction
4
+
5
+ attr_accessor :target
6
+
7
+ def initialize(x, y, absolute=true)
8
+ @target = Point.new(x,y)
9
+ super(absolute)
10
+ end
11
+
12
+ def to_command
13
+ command_code << "#{@target.x.to_s} #{@target.y.to_s}".gsub(/ -/,'-')
14
+ end
15
+
16
+ private
17
+ def command_code; ''; end;
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module Savage
2
+ module Directions
3
+ class QuadraticCurveTo < PointTarget
4
+ attr_accessor :control
5
+
6
+ def initialize(control_x, control_y, target_x, target_y, absolute=true)
7
+ @control = Point.new(control_x, control_y)
8
+ super(target_x, target_y, absolute)
9
+ end
10
+
11
+ def to_command(continuous=false)
12
+ command_code(continuous) << ((!continuous) ? "#{@control.x} #{@control.y} #{@target.x} #{@target.y}".gsub(/ -/,'-') : super().gsub(/[A-Za-z]/,''))
13
+ end
14
+
15
+ private
16
+ def command_code(continuous=false)
17
+ return (absolute?) ? 'Q' : 'q' unless continuous
18
+ (absolute?) ? 'T' : 't'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ module Savage
2
+ module Directions
3
+ class VerticalTo < CoordinateTarget
4
+ private
5
+ def command_code
6
+ (absolute?) ? 'V' : 'v'
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module Savage
2
+ class Path
3
+ require File.dirname(__FILE__) + "/sub_path"
4
+
5
+ def initialize(path_string=nil)
6
+ raise ArgumentError unless path_string.nil? || path_string.kind_of?(String)
7
+ end
8
+
9
+ def subpaths
10
+ return []
11
+ end
12
+
13
+ def to_command
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ module Savage
2
+ class SubPath
3
+ Directions.constants.each do |constant|
4
+ unless %w[PointTarget CoordinateTarget Point MoveTo].include? constant
5
+ sym = constant.gsub(/[A-Z]/) { |p| '_' + p.downcase }[1..-1].to_sym
6
+ define_method(sym) do |*args|
7
+ new_command = ("Savage::Directions::" << constant).constantize.new(*args)
8
+ @commands << new_command
9
+ new_command
10
+ end
11
+ end
12
+ end
13
+
14
+ attr_accessor :commands
15
+
16
+ def move_to(*args)
17
+ return nil unless @commands.empty?
18
+ new_move = Directions::MoveTo.new(*args)
19
+ @commands << new_move
20
+ new_move
21
+ end
22
+
23
+ def initialize
24
+ @commands = []
25
+ end
26
+
27
+ # FIXME - refactor this monstrosity
28
+ def to_command
29
+ prev_command = nil
30
+ command = ''
31
+ @commands.each do |dir|
32
+ this_command = dir.to_command
33
+ if dir.class == prev_command || (dir.class == Directions::LineTo && prev_command == Directions::MoveTo)
34
+ this_command.gsub!(/^[A-Za-z]/,'')
35
+ this_command = " " << this_command unless this_command.match(/^-/)
36
+ end
37
+ prev_command = dir.class
38
+ command << this_command
39
+ end
40
+ command
41
+ end
42
+
43
+ def closed?
44
+ @commands.last.kind_of? Directions::ClosePath
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,7 @@
1
+ module Savage
2
+ module Utils
3
+ def bool_to_int(value)
4
+ (value) ? 1 : 0
5
+ end
6
+ end
7
+ end
data/lib/savage.rb ADDED
@@ -0,0 +1,9 @@
1
+ SAVAGE_PATH = File.dirname(__FILE__) + "/savage/"
2
+ [
3
+ 'core_extensions/string',
4
+ 'utils',
5
+ 'direction',
6
+ 'path'
7
+ ].each do |library|
8
+ require SAVAGE_PATH + library
9
+ end
data/savage.gemspec ADDED
@@ -0,0 +1,100 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{savage}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jeremy Holland"]
12
+ s.date = %q{2010-05-02}
13
+ s.description = %q{A little gem for extracting and manipulating SVG vector path data.}
14
+ s.email = %q{jeremy@jeremypholland.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/savage.rb",
27
+ "lib/savage/core_extensions/string.rb",
28
+ "lib/savage/direction.rb",
29
+ "lib/savage/directions/arc_to.rb",
30
+ "lib/savage/directions/close_path.rb",
31
+ "lib/savage/directions/coordinate_target.rb",
32
+ "lib/savage/directions/cubic_curve_to.rb",
33
+ "lib/savage/directions/horizontal_to.rb",
34
+ "lib/savage/directions/line_to.rb",
35
+ "lib/savage/directions/move_to.rb",
36
+ "lib/savage/directions/point_target.rb",
37
+ "lib/savage/directions/quadratic_curve_to.rb",
38
+ "lib/savage/directions/vertical_to.rb",
39
+ "lib/savage/path.rb",
40
+ "lib/savage/sub_path.rb",
41
+ "lib/savage/utils.rb",
42
+ "savage.gemspec",
43
+ "spec/savage/directions/arc_to_spec.rb",
44
+ "spec/savage/directions/close_path_spec.rb",
45
+ "spec/savage/directions/cubic_curve_to_spec.rb",
46
+ "spec/savage/directions/horizontal_to_spec.rb",
47
+ "spec/savage/directions/line_to_spec.rb",
48
+ "spec/savage/directions/move_to_spec.rb",
49
+ "spec/savage/directions/point_spec.rb",
50
+ "spec/savage/directions/quadratic_curve_spec.rb",
51
+ "spec/savage/directions/vertical_to_spec.rb",
52
+ "spec/savage/path_spec.rb",
53
+ "spec/savage/sub_path_spec.rb",
54
+ "spec/savage_spec.rb",
55
+ "spec/shared/command.rb",
56
+ "spec/shared/coordinate_target.rb",
57
+ "spec/shared/direction.rb",
58
+ "spec/shared/point_target.rb",
59
+ "spec/spec.opts",
60
+ "spec/spec_helper.rb"
61
+ ]
62
+ s.homepage = %q{http://github.com/therubyneck/savage}
63
+ s.rdoc_options = ["--charset=UTF-8"]
64
+ s.require_paths = ["lib"]
65
+ s.rubygems_version = %q{1.3.6}
66
+ s.summary = %q{A little library to manipulate SVG path data}
67
+ s.test_files = [
68
+ "spec/savage/directions/arc_to_spec.rb",
69
+ "spec/savage/directions/close_path_spec.rb",
70
+ "spec/savage/directions/cubic_curve_to_spec.rb",
71
+ "spec/savage/directions/horizontal_to_spec.rb",
72
+ "spec/savage/directions/line_to_spec.rb",
73
+ "spec/savage/directions/move_to_spec.rb",
74
+ "spec/savage/directions/point_spec.rb",
75
+ "spec/savage/directions/quadratic_curve_spec.rb",
76
+ "spec/savage/directions/vertical_to_spec.rb",
77
+ "spec/savage/path_spec.rb",
78
+ "spec/savage/sub_path_spec.rb",
79
+ "spec/savage_spec.rb",
80
+ "spec/shared/command.rb",
81
+ "spec/shared/coordinate_target.rb",
82
+ "spec/shared/direction.rb",
83
+ "spec/shared/point_target.rb",
84
+ "spec/spec_helper.rb"
85
+ ]
86
+
87
+ if s.respond_to? :specification_version then
88
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
89
+ s.specification_version = 3
90
+
91
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
92
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
93
+ else
94
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
95
+ end
96
+ else
97
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
98
+ end
99
+ end
100
+
@@ -0,0 +1,96 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ include Savage::Directions
4
+
5
+ describe ArcTo do
6
+ def dir_class; ArcTo; end
7
+ def create_relative; ArcTo.new(100,200,300,true,false,400,500,false); end
8
+ def command_code; 'a'; end
9
+
10
+ before :each do
11
+ @dir = dir_class.new(100,200,300,true,false,400,500)
12
+ end
13
+
14
+ include DirectionShared
15
+
16
+ it 'should have a target' do
17
+ @dir.respond_to?(:target).should == true
18
+ @dir.target.class.should == Point
19
+ end
20
+ it 'should have a radius' do
21
+ @dir.respond_to?(:radius).should == true
22
+ @dir.radius.class.should == Point
23
+ end
24
+ it 'should have a large arc based on the constructor argument' do
25
+ @dir.respond_to?(:large_arc).should == true
26
+ @dir.large_arc.should == true
27
+ end
28
+ it 'should have a sweep based on the constructor argument' do
29
+ @dir.respond_to?(:sweep).should == true
30
+ @dir.sweep.should == false
31
+ end
32
+ it 'should have a rotation based on the constructor arugment' do
33
+ @dir.respond_to?(:rotation).should == true
34
+ @dir.rotation.should == 300
35
+ end
36
+ it 'should have an accessible target x, based on the constructor argument' do
37
+ @dir.target.x.should == 400
38
+ end
39
+ it 'should have an accessible target y, based on the constructor argument' do
40
+ @dir.target.y.should == 500
41
+ end
42
+ it 'should have an accessible x radius, based on the constructor argument' do
43
+ @dir.radius.x.should == 100
44
+ end
45
+ it 'should have an accessible y radius, based on the constructor argument' do
46
+ @dir.radius.y.should == 200
47
+ end
48
+ it 'should be constructed with at least x and y radii, rotation, large arc, sweep, and target x and y parameters' do
49
+ lambda { dir_class.new }.should raise_error
50
+ lambda { dir_class.new 45 }.should raise_error
51
+ lambda { dir_class.new 45, 50 }.should raise_error
52
+ lambda { dir_class.new 45, 50, 60 }.should raise_error
53
+ lambda { dir_class.new 45, 50, 60, true }.should raise_error
54
+ lambda { dir_class.new 45, 50, 60, true, true }.should raise_error
55
+ lambda { dir_class.new 45, 50, 60, true, true, 100 }.should raise_error
56
+ lambda { dir_class.new 45, 50, 60, true, true, 100, 200 }.should_not raise_error
57
+ end
58
+ it 'should be relative if constructed with a false eighth parameter' do
59
+ direction = dir_class.new 45, 50, 60, true, true, 100, 200, false
60
+ direction.absolute?.should == false
61
+ end
62
+ it 'should be absolute if constructed with a true eighth parameter' do
63
+ direction = dir_class.new 45, 50, 60, true, true, 100, 200, true
64
+ direction.absolute?.should == true
65
+ end
66
+ it 'should be absolute if constructed with only seven parameters' do
67
+ direction = dir_class.new 45, 50, 60, true, true, 100, 200
68
+ direction.absolute?.should == true
69
+ end
70
+ describe '#to_command' do
71
+ it 'should have exactly 7 numerical parameters' do
72
+ extract_coordinates(@dir.to_command).length.should == 7
73
+ end
74
+ it 'should show the provided x radius value as the first parameter' do
75
+ extract_coordinates(@dir.to_command)[0].should == 100
76
+ end
77
+ it 'should show the provided y radius value as the second parameter' do
78
+ extract_coordinates(@dir.to_command)[1].should == 200
79
+ end
80
+ it 'should show the provided rotation value as the third parameter' do
81
+ extract_coordinates(@dir.to_command)[2].should == 300
82
+ end
83
+ it 'should show the integer interpretation of the provided large arc value as the fourth parameter' do
84
+ extract_coordinates(@dir.to_command)[3].should == 1
85
+ end
86
+ it 'should show the integer interpretation of the provided sweep value as the fifth parameter' do
87
+ extract_coordinates(@dir.to_command)[4].should == 0
88
+ end
89
+ it 'should show the provided target x value as the sixth parameter' do
90
+ extract_coordinates(@dir.to_command)[5].should == 400
91
+ end
92
+ it 'should show the provided target y value as the seventh parameter' do
93
+ extract_coordinates(@dir.to_command)[6].should == 500
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ include Savage::Directions
4
+
5
+ describe ClosePath do
6
+ before :each do
7
+ @dir = ClosePath.new()
8
+ end
9
+ def create_relative; ClosePath.new(false); end
10
+ def command_code; 'z'; end
11
+ include DirectionShared
12
+ it 'should be constructed with with either no parameters or a single boolean parameter' do
13
+ lambda { ClosePath.new }.should_not raise_error
14
+ lambda { ClosePath.new true }.should_not raise_error
15
+ lambda { ClosePath.new 45, 50 }.should raise_error
16
+ end
17
+ it 'should be relative if constructed with a false parameter' do
18
+ direction = ClosePath.new(false)
19
+ direction.absolute?.should == false
20
+ end
21
+ it 'should be absolute if constructed with a false parameter' do
22
+ direction = ClosePath.new(true)
23
+ direction.absolute?.should == true
24
+ end
25
+ it 'should be absolute if constructed with no parameters' do
26
+ direction = ClosePath.new()
27
+ direction.absolute?.should == true
28
+ end
29
+ end