Another commit
authorNeil Smith <neil.github@njae.me.uk>
Sun, 25 Sep 2011 18:35:03 +0000 (19:35 +0100)
committerNeil Smith <neil.github@njae.me.uk>
Sun, 25 Sep 2011 18:35:03 +0000 (19:35 +0100)
lib/erd_handler.rb
lib/erd_handler/erd.rb
spec/erd_handler/erd_spec.rb
spec/fixtures/single_box_erd.xml
spec/spec_helper.rb

index 501d016137b668ffae840cf0a17d8d9f8cbd7295..6524d3140db8abe649d81d0138cbe8c7f32706c6 100644 (file)
@@ -1,4 +1,12 @@
-require 'erd_handler/erd'
+require 'bundler/setup'
+
 require "rexml/document"
 include REXML  
 
+require "graph.njae"
+include GraphNjae
+
+require 'erd_handler/erd'
+require 'erd_handler/box'
+require 'erd_handler/link'
+
index b9e6da17d02ba3bbb812e665ac728698617b3b17..a0c94e4d931a33e98295f4a48cd7bf59949d74d5 100644 (file)
@@ -1,8 +1,23 @@
-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
+      self
     end
   end
-end
+end
\ No newline at end of file
index ec75afeb416448d92dd0f0fba9f584384592ee0a..164a91eb3f170e8bd9c0948584df9f8d3b7231b1 100644 (file)
@@ -1,19 +1,34 @@
 require 'spec_helper'
 
-module Erd
+module ErdHandler
   describe Erd do
     let(:input) { double('input').as_null_object }
     let(:output) { double('output').as_null_object }
     let(:erd) { Erd.new(input, output) }
     
-    describe "#read" do
-      it "reads a single box" do
-       doc = Document.new File.new("spec/fixtures/single_box_erd.xml")
-       erd = Erd.new doc
-       erd.mark.should == 6.5
-       erd.boxes.length.should == 1
-       
+    describe "#initialize" do
+      it "creates an empty ERD" do
+        erd = Erd.new
+        erd.mark.should be_nil
+        erd.should have(0).vertices
+        erd.should have(0).edges       
       end
-    end # #read
+      
+      it "reads and creates a single box" do
+        erd = Erd.new(File.new("spec/fixtures/single_box_erd.xml"))
+        erd.mark.should == 6.5
+        erd.should have(1).vertices
+        erd.should have(0).edges
+      end
+      
+      it "reads and creates two boxes with an edge joining them" do
+        erd = Erd.new(File.new("spec/fixtures/two_boxes_one_link_erd.xml"))
+        erd.mark.should == 4.5
+        erd.should have(2).vertices
+        erd.should have(1).edges
+      end
+      
+      it "reads and creates a box with a self-loop"
+    end # #initialize
   end
 end
\ No newline at end of file
index 45e7118901965dd583192c3cae40390ad8a13c5b..e339b2b781493ef12bfa73ccde2a2c6de6609bd3 100644 (file)
@@ -5,6 +5,6 @@
 <box id="0" name="Client" mark="0.0">
   <location x="33.0" y="43.0"/>
   <size width="80.0" height="40.0"/>
-  <comment></comment>
+  <comment>A comment</comment>
 </box> 
 </Drawing>
index 3c4ea53c2167f3d8eaa81b17ca73a841b8f54294..e82322eafcc4a3d95c53ca9ecc899043effd9fba 100644 (file)
@@ -1,3 +1,7 @@
+require 'rexml/document.rb'
+include REXML  
+
+require 'graph.njae'
+include GraphNjae
+
 require 'erd_handler'
-require "rexml/document"
-include REXML  
\ No newline at end of file