X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=lib%2Ferd_handler%2Fbox.rb;h=244b411fc597e663ba4b637685dcf5ddf1f177cc;hb=fdc3bc03b2d7759927ae34d5382d2168be6a2bae;hp=7389955d4b58d2927efc70703e9b3e966f799ded;hpb=e63ce01b6c3d62ec3b7354dc6364f43ce3de5d5e;p=erd-marker.git diff --git a/lib/erd_handler/box.rb b/lib/erd_handler/box.rb index 7389955..244b411 100644 --- a/lib/erd_handler/box.rb +++ b/lib/erd_handler/box.rb @@ -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