From: Neil Smith Date: Fri, 29 Jun 2012 14:57:29 +0000 (+0100) Subject: Started on abstract ERDs X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=676318af3226f0170d556b419b53e5c4e497acda;p=erd-marker.git Started on abstract ERDs --- diff --git a/Gemfile.lock b/Gemfile.lock index d440e9c..8d44c45 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 index 0000000..64dcb9c --- /dev/null +++ b/bundler_stubs/autospec @@ -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 index 0000000..c70e238 --- /dev/null +++ b/bundler_stubs/htmldiff @@ -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 index 0000000..8e3524a --- /dev/null +++ b/bundler_stubs/ldiff @@ -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 index 0000000..26c7a2d --- /dev/null +++ b/bundler_stubs/rake @@ -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 index 0000000..90f2517 --- /dev/null +++ b/bundler_stubs/ri @@ -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 index 0000000..0c86b5c --- /dev/null +++ b/bundler_stubs/rspec @@ -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') diff --git a/lib/erd_handler.rb b/lib/erd_handler.rb index 241db56..bea10a1 100644 --- a/lib/erd_handler.rb +++ b/lib/erd_handler.rb @@ -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 index 0000000..c5e2a3a --- /dev/null +++ b/lib/erd_handler/abstract_erd.rb @@ -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 index 0000000..67fe7c7 --- /dev/null +++ b/spec/erd_handler/abstract_erd_spec.rb @@ -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 diff --git a/spec/erd_handler/erd_spec.rb b/spec/erd_handler/erd_spec.rb index 6b33dd8..f6f636d 100644 --- a/spec/erd_handler/erd_spec.rb +++ b/spec/erd_handler/erd_spec.rb @@ -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 index 0000000..356c943 --- /dev/null +++ b/spec/fixtures/two_boxes_one_contained_erd.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file