75543eb22674b1dcc92f5734dcc6ea6366a929e3
[erd-marker.git] / lib / erd_handler / box.rb
1 module ErdHandler
2 class Box < Vertex
3 def initialize(box_element = nil)
4 super()
5 read(box_element) unless box_element.nil?
6 self
7 end # initialize
8
9 def read(box_element)
10 self.id = box_element.attributes["id"].to_i
11 self.name = Label.new box_element.attributes["name"]
12 self.mark = box_element.attributes["mark"].to_f
13
14 self.x = box_element.elements["location"].attributes["x"].to_f
15 self.y = box_element.elements["location"].attributes["y"].to_f
16 self.width = box_element.elements["size"].attributes["width"].to_f
17 self.height = box_element.elements["size"].attributes["height"].to_f
18 self.comment = box_element.elements["comment"].text
19 self
20 end
21
22 def contains?(other)
23 self.x < other.x and self.x + self.width > other.x + other.width and
24 self.y < other.y and self.y + self.height > other.y + other.height
25 end
26
27 def within?(other)
28 other.contains?(self)
29 end
30
31 end
32 end