Commit c7363e6
Changed files (2)
lib
scale
shapes
spec
shapes
lib/scale/shapes/path.rb
@@ -11,12 +11,12 @@ module Scale
command("L #{x} #{y}")
end
- def horizontal(n)
- command("H #{n}")
+ def horizontal(n, relative: false)
+ command("#{relative ? "h" : "H"} #{n}")
end
- def vertical(n)
- command("V #{n}")
+ def vertical(n, relative: false)
+ command("#{relative ? "v" : "V"} #{n}")
end
def close_path
spec/shapes/path_spec.rb
@@ -32,11 +32,24 @@ describe Scale::Path do
XML
expect(subject.to_xml).to eql(expected)
end
+
+ it 'moves horizontally using relative position' do
+ subject.move_to(x: 10, y: 10)
+ subject.horizontal(90, relative: true)
+ expected = <<-XML
+<?xml version="1.0"?>
+<path d="M10 10 h 90"/>
+ XML
+ expect(subject.to_xml).to eql(expected)
+ end
end
describe "#vertial" do
- it 'draws a horizontal line' do
+ before :each do
subject.move_to(x: 10, y: 10)
+ end
+
+ it 'draws a vertical line' do
subject.vertical(90)
expected = <<-XML
<?xml version="1.0"?>
@@ -44,6 +57,15 @@ describe Scale::Path do
XML
expect(subject.to_xml).to eql(expected)
end
+
+ it 'draws a vertical line relative to the current position' do
+ subject.vertical(90, relative: true)
+ expected = <<-XML
+<?xml version="1.0"?>
+<path d="M10 10 v 90"/>
+ XML
+ expect(subject.to_xml).to eql(expected)
+ end
end
describe "#close_path" do
@@ -74,5 +96,4 @@ describe Scale::Path do
expect(subject.to_xml).to eql(expected)
end
end
-
end