Commit 7627039

mo khan <mo@mokhan.ca>
2015-04-08 18:23:44
define a circle.
1 parent 5776807
Changed files (3)
lib/scale/circle.rb
@@ -0,0 +1,17 @@
+module Scale
+  class Circle
+    include Node
+    include Virtus.model
+    attribute :cx, Integer
+    attribute :cy, Integer
+    attribute :r, Integer
+
+    def xml_tag
+      :circle
+    end
+
+    def attributes
+      super.delete_if { |key, value| value.nil? }
+    end
+  end
+end
lib/scale.rb
@@ -2,6 +2,7 @@ require "scale/version"
 require "scale/node"
 require "scale/svg"
 require "scale/rectangle"
+require "scale/circle"
 
 module Scale
   # Your code goes here... NOT!
spec/circle_spec.rb
@@ -0,0 +1,25 @@
+
+describe Scale::Circle do
+  it { expect(subject.xml_tag).to eql(:circle) }
+
+  describe "#attributes" do
+    it "includes the radius" do
+      subject.r = 10
+      expect(subject.attributes).to include(r: 10)
+    end
+
+    it "includes the x position of the center of the circle" do
+      subject.cx = 10
+      expect(subject.attributes).to include(cx: 10)
+    end
+
+    it "includes the y position of the center of the circle" do
+      subject.cy = 10
+      expect(subject.attributes).to include(cy: 10)
+    end
+
+    it "skips attributes that are not specified" do
+      expect(subject.attributes).to be_empty
+    end
+  end
+end