End of the day
[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 = 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 self
21 end
22 end
23 end