summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-04-08 12:23:44 -0600
committermo khan <mo@mokhan.ca>2015-04-08 12:23:44 -0600
commit76270390d1e5c2e98e411761a9855280474d6762 (patch)
tree8b2ed98e3a9661ec957d29b44a85918dadc73b11
parent57768072f51abde9825de1f4e5bf1b4f33e0e035 (diff)
define a circle.
-rw-r--r--lib/scale.rb1
-rw-r--r--lib/scale/circle.rb17
-rw-r--r--spec/circle_spec.rb25
3 files changed, 43 insertions, 0 deletions
diff --git a/lib/scale.rb b/lib/scale.rb
index 02ffc09..e8bc61f 100644
--- a/lib/scale.rb
+++ b/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!
diff --git a/lib/scale/circle.rb b/lib/scale/circle.rb
new file mode 100644
index 0000000..edf8e6c
--- /dev/null
+++ b/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
diff --git a/spec/circle_spec.rb b/spec/circle_spec.rb
new file mode 100644
index 0000000..27486b8
--- /dev/null
+++ b/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