Started on abstract ERDs
authorNeil Smith <neil.github@njae.me.uk>
Fri, 29 Jun 2012 14:57:29 +0000 (15:57 +0100)
committerNeil Smith <neil.github@njae.me.uk>
Fri, 29 Jun 2012 14:57:29 +0000 (15:57 +0100)
12 files changed:
Gemfile.lock
bundler_stubs/autospec [new file with mode: 0755]
bundler_stubs/htmldiff [new file with mode: 0755]
bundler_stubs/ldiff [new file with mode: 0755]
bundler_stubs/rake [new file with mode: 0755]
bundler_stubs/ri [new file with mode: 0755]
bundler_stubs/rspec [new file with mode: 0755]
lib/erd_handler.rb
lib/erd_handler/abstract_erd.rb [new file with mode: 0644]
spec/erd_handler/abstract_erd_spec.rb [new file with mode: 0644]
spec/erd_handler/erd_spec.rb
spec/fixtures/two_boxes_one_contained_erd.xml [new file with mode: 0644]

index d440e9ca5807db2dedee9b11b5a3694975ad8e8e..8d44c452abb6e42cf6b926b422b2bf2067c7d10b 100644 (file)
@@ -2,9 +2,9 @@ GEM
   remote: http://rubygems.org/
   specs:
     diff-lcs (1.1.3)
-    graph.njae (0.2.3)
+    graph.njae (0.2.4)
     json (1.6.5)
-    porter2stemmer (1.0.0)
+    porter2stemmer (1.0.1)
     rake (0.9.2.2)
     rdoc (3.12)
       json (~> 1.4)
diff --git a/bundler_stubs/autospec b/bundler_stubs/autospec
new file mode 100755 (executable)
index 0000000..64dcb9c
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'autospec' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+  Pathname.new(__FILE__).realpath)
+
+require 'rubygems'
+require 'bundler/setup'
+
+load Gem.bin_path('rspec-core', 'autospec')
diff --git a/bundler_stubs/htmldiff b/bundler_stubs/htmldiff
new file mode 100755 (executable)
index 0000000..c70e238
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'htmldiff' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+  Pathname.new(__FILE__).realpath)
+
+require 'rubygems'
+require 'bundler/setup'
+
+load Gem.bin_path('diff-lcs', 'htmldiff')
diff --git a/bundler_stubs/ldiff b/bundler_stubs/ldiff
new file mode 100755 (executable)
index 0000000..8e3524a
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'ldiff' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+  Pathname.new(__FILE__).realpath)
+
+require 'rubygems'
+require 'bundler/setup'
+
+load Gem.bin_path('diff-lcs', 'ldiff')
diff --git a/bundler_stubs/rake b/bundler_stubs/rake
new file mode 100755 (executable)
index 0000000..26c7a2d
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'rake' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+  Pathname.new(__FILE__).realpath)
+
+require 'rubygems'
+require 'bundler/setup'
+
+load Gem.bin_path('rake', 'rake')
diff --git a/bundler_stubs/ri b/bundler_stubs/ri
new file mode 100755 (executable)
index 0000000..90f2517
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'ri' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+  Pathname.new(__FILE__).realpath)
+
+require 'rubygems'
+require 'bundler/setup'
+
+load Gem.bin_path('rdoc', 'ri')
diff --git a/bundler_stubs/rspec b/bundler_stubs/rspec
new file mode 100755 (executable)
index 0000000..0c86b5c
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'rspec' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+  Pathname.new(__FILE__).realpath)
+
+require 'rubygems'
+require 'bundler/setup'
+
+load Gem.bin_path('rspec-core', 'rspec')
index 241db56426ace2871c6e77a53b4b0927cff1b7ba..bea10a1473cd1940128d95031a6551592f198d44 100644 (file)
@@ -12,4 +12,5 @@ require 'erd_handler/label'
 require 'erd_handler/erd'
 require 'erd_handler/box'
 require 'erd_handler/link'
+require 'erd_handler/abstract_erd'
 
diff --git a/lib/erd_handler/abstract_erd.rb b/lib/erd_handler/abstract_erd.rb
new file mode 100644 (file)
index 0000000..c5e2a3a
--- /dev/null
@@ -0,0 +1,44 @@
+module ErdHandler
+  class AbstractErd < Graph
+    def initialize(source = nil)
+      super()
+      abstract(source) unless source.nil?
+      self
+    end
+    
+    # Create an abstract ERD from a base ERD.
+    # An abstract ERD has an additional node for each link
+    def abstract(erd)
+      self.mark = erd.mark
+      self.name = erd.name
+      erd.vertices.each do |v|
+        self << AbstractBox.new(v)
+        # also do links for containment
+      end
+      erd.edges.each do |e|
+        link_vertex = AbstractEdge.new(e)
+        e.connections.each do |c|
+          # find the abstract vertex at this end
+          # connect the abstract link to it
+        end
+      end
+      self
+    end
+  end
+  
+  class AbstractBox < Vertex
+    def initialize(souce = nil)
+      super()
+      self.base_vertex = source unless source.nil?
+      self
+    end
+  end
+  
+  class AbstractEdge < Vertex
+    def initialize(source = nil)
+      super()
+      self.base_vertex = source unless source.nil?
+      self
+    end
+  end
+end
diff --git a/spec/erd_handler/abstract_erd_spec.rb b/spec/erd_handler/abstract_erd_spec.rb
new file mode 100644 (file)
index 0000000..67fe7c7
--- /dev/null
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+module ErdHandler
+  describe AbstractErd do
+    describe "#initialize" do
+      it "creates an empty abstract ERD" do
+        aerd = AbstractErd.new
+        aerd.should have(0).vertices
+        aerd.should have(0).edges       
+      end
+      
+      it "reads and creates a single box" do
+        erd = Erd.new(File.new("spec/fixtures/single_box_erd.xml"))
+        aerd = AbstractErd.new(erd)
+        aerd.mark.should == 6.5
+        aerd.should have(1).vertices
+        aerd.should have(0).edges
+      end
+    end # #initialize
+    
+    describe "#abstract" do
+      it "reads and creates a single box" do
+        erd = Erd.new(File.new("spec/fixtures/single_box_erd.xml"))
+        aerd = AbstractErd.new
+        aerd.abstract erd
+        aerd.mark.should == 6.5
+        aerd.should have(1).vertices
+        aerd.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"))
+        aerd = AbstractErd.new
+        aerd.abstract erd
+        aerd.mark.should == 4.5
+        aerd.should have(3).vertices
+        aerd.should have(2).edges
+      end
+    end # #abstract
+    
+  end
+end
index 6b33dd8e3dbfc92238b3c76aadcb5b5201103079..f6f636d10dec7f9c08a06be647fce482bd7814ea 100644 (file)
@@ -4,7 +4,7 @@ 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) }
+    let(:erd) { Erd.new(input) }
     
     describe "#initialize" do
       it "creates an empty ERD" do
diff --git a/spec/fixtures/two_boxes_one_contained_erd.xml b/spec/fixtures/two_boxes_one_contained_erd.xml
new file mode 100644 (file)
index 0000000..356c943
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><Drawing
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   name="Untitled" mark="4.5">
+
+<box id="0" name="Unit" mark="0.0">
+  <location x="87.0" y="69.0"/>
+  <size width="80.0" height="40.0"/>
+  <comment></comment>
+</box>
+
+<box id="1" name="Employee" mark="0.0">
+  <location x="80.0" y="60.0"/>
+  <size width="180.0" height="140.0"/>
+  <comment></comment>
+</box>
+
+</Drawing>
\ No newline at end of file