Commit f94c815
Changed files (2)
lib
scale
shapes
spec
shapes
lib/scale/shapes/path.rb
@@ -7,6 +7,18 @@ module Scale
self.d="M#{x} #{y}"
end
+ def line_to(x:, y:)
+ self.d = "#{self.d} L #{x} #{y}"
+ end
+
+ def horizontal(n)
+ self.d = "#{self.d} H #{n}"
+ end
+
+ def vertical(n)
+ self.d = "#{self.d} V #{n}"
+ end
+
def xml_tag
:path
end
spec/shapes/path_spec.rb
@@ -1,10 +1,48 @@
describe Scale::Path do
- it 'moves' do
- subject.move_to(x: 10, y: 10)
- expected = <<-XML
+ describe "#move_to" do
+ it 'moves' do
+ subject.move_to(x: 10, y: 10)
+ expected = <<-XML
<?xml version="1.0"?>
<path d="M10 10"/>
- XML
- expect(subject.to_xml).to eql(expected)
+ XML
+ expect(subject.to_xml).to eql(expected)
+ end
+ end
+
+ describe "#line_to" do
+ it 'draws a line to the x and y coordinate' do
+ subject.move_to(x: 10, y: 10)
+ subject.line_to(x: 20, y: 20)
+ expected = <<-XML
+<?xml version="1.0"?>
+<path d="M10 10 L 20 20"/>
+ XML
+ expect(subject.to_xml).to eql(expected)
+ end
+ end
+
+ describe "#horizontal" do
+ it 'draws a horizontal line' do
+ subject.move_to(x: 10, y: 10)
+ subject.horizontal(90)
+ 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
+ subject.move_to(x: 10, y: 10)
+ subject.vertical(90)
+ expected = <<-XML
+<?xml version="1.0"?>
+<path d="M10 10 V 90"/>
+ XML
+ expect(subject.to_xml).to eql(expected)
+ end
end
end