X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=lib%2Ferd_handler%2Ferd.rb;h=142f575d8851044d9299090b069599526aad7480;hb=5cb26987412346fc34cb344d7b169c0784f1da77;hp=b9e6da17d02ba3bbb812e665ac728698617b3b17;hpb=29a64f0a2207a69d136c6f67edcd6855af8152d8;p=erd-marker.git

diff --git a/lib/erd_handler/erd.rb b/lib/erd_handler/erd.rb
index b9e6da1..142f575 100644
--- a/lib/erd_handler/erd.rb
+++ b/lib/erd_handler/erd.rb
@@ -1,8 +1,26 @@
-module Erd
-  class Erd
+module ErdHandler
+  class Erd < Graph
     def initialize(source = nil)
-      doc = Document.new source
-      raise InvalidErdFile unless doc.elements.length == 1 and doc.elements[1].name.downcase == 'drawing'
+      super()
+      read(source) unless source.nil?
+      self
+    end
+    
+    def read(source)
+      doc = Document.new(source)
+      raise InvalidErdFile unless doc.elements.to_a.length == 1 and doc.elements[1].name.downcase == 'drawing'
+      self.mark = doc.elements['Drawing'].attributes["mark"].to_f
+      self.name = doc.elements['Drawing'].attributes["name"]
+      doc.elements.each('Drawing/box') do |box_element|
+        self << Box.new(box_element)
+      end
+      doc.elements.each('Drawing/link') do |link_element|
+        self << Link.new(link_element, self.vertices)
+      end
+      doc.elements.each('Drawing/selfLink') do |link_element|
+        self << Link.new(link_element, self.vertices)
+      end
+      self
     end
   end
 end