Commit 5776807

mo khan <mo@mokhan.ca>
2015-04-08 18:17:40
use virtus for attribute definitions.
1 parent efd77e1
Changed files (2)
lib/scale/rectangle.rb
@@ -1,20 +1,23 @@
+require 'virtus'
+
 module Scale
   class Rectangle
     include Node
-    attr_accessor :height, :width, :fill, :x, :y, :rx, :ry
-
-    def initialize(width: nil, height: nil, fill: nil)
-      @width = width
-      @height = height
-      @fill = fill
-    end
+    include Virtus.model
+    attribute :width, String
+    attribute :height, String
+    attribute :fill, String
+    attribute :x, Integer
+    attribute :y, Integer
+    attribute :rx, Integer
+    attribute :ry, Integer
 
     def xml_tag
       :rect
     end
 
     def attributes
-      { width: width, height: height, fill: fill, x: x, y: y, rx: rx, ry: ry }.delete_if { |key, value| value.nil? }
+      super.delete_if { |key, value| value.nil? }
     end
   end
 end
scale.gemspec
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
   spec.require_paths = ["lib"]
 
   spec.add_dependency "nokogiri", "~> 1.6.6"
+  spec.add_dependency "virtus", "~> 1.0"
   spec.add_development_dependency "bundler", "~> 1.9"
   spec.add_development_dependency "rake", "~> 10.0"
   spec.add_development_dependency "rspec", "~> 3.2"