From e63ce01b6c3d62ec3b7354dc6364f43ce3de5d5e Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sun, 25 Sep 2011 19:36:31 +0100 Subject: [PATCH] Another commit --- .rspec | 1 + Gemfile | 14 +++++++++ Gemfile.lock | 25 ++++++++++++++++ Rakefile | 35 +++++++++++++++++++++++ lib/erd_handler/box.rb | 23 +++++++++++++++ lib/erd_handler/link.rb | 15 ++++++++++ spec/fixtures/two_boxes_one_link_erd.xml | 36 ++++++++++++++++++++++++ 7 files changed, 149 insertions(+) create mode 100644 .rspec create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Rakefile create mode 100644 lib/erd_handler/box.rb create mode 100644 lib/erd_handler/link.rb create mode 100644 spec/fixtures/two_boxes_one_link_erd.xml diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..4e1e0d2 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..6444095 --- /dev/null +++ b/Gemfile @@ -0,0 +1,14 @@ +source "http://rubygems.org" +# Add dependencies required to use your gem here. +# Example: +# gem "activesupport", ">= 2.3.5" + +# Add dependencies to develop your gem here. +# Include everything needed to run rake, tests, features, etc. +group :development do + gem "rspec", "~> 2.6.0" + gem "bundler", "~> 1.0.0" + gem "rdoc" + gem "rake" + gem "graph.njae", "0.2.1" +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..dca8027 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,25 @@ +GEM + remote: http://rubygems.org/ + specs: + diff-lcs (1.1.2) + graph.njae (0.2.1) + rake (0.9.2) + rdoc (3.7) + rspec (2.6.0) + rspec-core (~> 2.6.0) + rspec-expectations (~> 2.6.0) + rspec-mocks (~> 2.6.0) + rspec-core (2.6.4) + rspec-expectations (2.6.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.6.0) + +PLATFORMS + ruby + +DEPENDENCIES + bundler (~> 1.0.0) + graph.njae (= 0.2.1) + rake + rdoc + rspec (~> 2.6.0) diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..e0a0436 --- /dev/null +++ b/Rakefile @@ -0,0 +1,35 @@ +# encoding: utf-8 + +require 'rubygems' +require 'bundler' +begin + Bundler.setup(:default, :development) +rescue Bundler::BundlerError => e + $stderr.puts e.message + $stderr.puts "Run `bundle install` to install missing gems" + exit e.status_code +end +require 'rake' + +require 'rspec/core' +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:spec) do |spec| + spec.pattern = FileList['spec/**/*_spec.rb'] +end + +RSpec::Core::RakeTask.new(:rcov) do |spec| + spec.pattern = 'spec/**/*_spec.rb' + spec.rcov = true +end + +task :default => :spec + +require 'rdoc/task' +RDoc::Task.new do |rdoc| + version = File.exist?('VERSION') ? File.read('VERSION') : "" + + rdoc.rdoc_dir = 'rdoc' + rdoc.title = "graph.njae #{version}" + rdoc.rdoc_files.include('README*') + rdoc.rdoc_files.include('lib/**/*.rb') +end diff --git a/lib/erd_handler/box.rb b/lib/erd_handler/box.rb new file mode 100644 index 0000000..7389955 --- /dev/null +++ b/lib/erd_handler/box.rb @@ -0,0 +1,23 @@ +module ErdHandler + class Box < Vertex + def initialize(box_element = nil) + super() + read(box_element) unless box_element.nil? + self + end # initialize + + def read(box_element) + self.id = box_element.attributes["id"].to_i + self.name = box_element.attributes["name"] + self.mark = box_element.attributes["mark"].to_f + + self.x = box_element.elements["location"].attributes["x"].to_f + self.y = box_element.elements["location"].attributes["y"].to_f + self.width = box_element.elements["size"].attributes["width"].to_f + self.height = box_element.elements["size"].attributes["height"].to_f + self.comment = box_element.elements["comment"].text + self + end + + end +end diff --git a/lib/erd_handler/link.rb b/lib/erd_handler/link.rb new file mode 100644 index 0000000..f8ebc19 --- /dev/null +++ b/lib/erd_handler/link.rb @@ -0,0 +1,15 @@ +module ErdHandler + class Link < Edge + def initialize(link_element = nil, vertices = nil) + super() + read(link_element, vertices) unless link_element.nil? + self + end + + def read(link_element, vertices) + self.id = link_element.attributes["id"].to_i + self.mark = link_element.attributes["mark"].to_f + + end + end +end \ No newline at end of file diff --git a/spec/fixtures/two_boxes_one_link_erd.xml b/spec/fixtures/two_boxes_one_link_erd.xml new file mode 100644 index 0000000..3e0f74d --- /dev/null +++ b/spec/fixtures/two_boxes_one_link_erd.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.34.1