Added simplecov
[erd-marker.git] / lib / erd_handler / erd.rb
1 module ErdHandler
2 class Erd < Graph
3 def initialize(source = nil)
4 super()
5 read(source) unless source.nil?
6 self
7 end
8
9 def read(source)
10 doc = Document.new(source)
11 raise InvalidErdFile unless doc.elements.to_a.length == 1 and doc.elements[1].name.downcase == 'drawing'
12 self.mark = doc.elements['Drawing'].attributes["mark"].to_f
13 self.name = Label.new doc.elements['Drawing'].attributes["name"]
14 doc.elements.each('Drawing/box') do |box_element|
15 self << Box.new(box_element)
16 end
17 doc.elements.each('Drawing/link') do |link_element|
18 self << Link.new(link_element, self.vertices)
19 end
20 doc.elements.each('Drawing/selfLink') do |link_element|
21 self << Link.new(link_element, self.vertices)
22 end
23 self
24 end
25
26 # The minimal meaningful units of an ERD are:
27 # Each box in isolation
28 # Each link, with the associated boxes at its ends
29 def mmus
30 mmus = []
31 self.vertices.each do |b|
32 mmu = Erd.new
33 mmu << b
34 mmus << mmu
35 end
36 self.edges.each do |l|
37 mmu = Erd.new
38 l.vertices.each do |b|
39 mmu << b
40 end
41 mmu << l
42 mmus << mmu
43 end
44 mmus
45 end
46
47 end
48 end