Fiddling around with labels and boxes
[erd-marker.git] / lib / erd_handler / box.rb
index 7389955d4b58d2927efc70703e9b3e966f799ded..244b411fc597e663ba4b637685dcf5ddf1f177cc 100644 (file)
@@ -8,7 +8,7 @@ module ErdHandler
     
     def read(box_element)
       self.id = box_element.attributes["id"].to_i
-      self.name = box_element.attributes["name"]
+      self.name = Label.new box_element.attributes["name"]
       self.mark = box_element.attributes["mark"].to_f
       
       self.x = box_element.elements["location"].attributes["x"].to_f
@@ -19,5 +19,18 @@ module ErdHandler
       self
     end
     
+    def contains?(other)
+      self.x < other.x and self.x + self.width > other.x + other.width and 
+          self.y < other.y and self.y + self.height > other.y + other.height
+    end
+
+    def within?(other)
+      other.contains?(self)
+    end
+    
+    def similarity(other)
+      1.0 - self.name.edit_distance(other.name) / self.name.length.to_f
+    end
+    
   end
 end