From 76270390d1e5c2e98e411761a9855280474d6762 Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 8 Apr 2015 12:23:44 -0600 Subject: define a circle. --- lib/scale.rb | 1 + lib/scale/circle.rb | 17 +++++++++++++++++ spec/circle_spec.rb | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 lib/scale/circle.rb create mode 100644 spec/circle_spec.rb 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 -- cgit v1.2.3