class DomGlancy::DOMElement

Attributes

height[RW]
id[RW]
element looks like this in archive.

{“id”=>“”, “height”=>238, “visible”=>true, “tag”=>“DIV”, “width”=>720, “class”=>“grid”, “left”=>43, “top”=>14}

klass[RW]
left[RW]
similarity[RW]
style[RW]
tag[RW]
top[RW]
visible[RW]
width[RW]

Public Class Methods

new(h = {}) click to toggle source
# File lib/dom_glancy/element.rb, line 17
def initialize(h = {})
  @tag        = h['tag']
  @left       = h['left']
  @top        = h['top']
  @height     = h['height']
  @width      = h['width']
  @klass      = h['class']
  @id         = h['id']
  @style      = h['style']
  @visible    = h['visible']
  @similarity = h['similarity'] || 0
end

Public Instance Methods

all_same?(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 36
def all_same?(anOther)
  same = same_element?(anOther)     &&
      similar_size?(anOther, 0)     &&
      similar_location?(anOther, 0) &&
      same_size?(anOther)           &&
      same_visibility?(anOther)
end
change_info(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 119
def change_info(anOther)
  info = []
  if same_element?(anOther)
    info << 'left' unless similar_left?(anOther, @similarity)
    info << 'top' unless similar_top?(anOther, @similarity)
    info << 'height' unless similar_height?(anOther, @similarity)
    info << 'width' unless similar_width?(anOther, @similarity)
  end
  info
end
change_level(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 115
def change_level(anOther)
  change_info(anOther).length
end
close_enough?(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 44
def close_enough?(anOther)
  r = same_element?(anOther)                  &&
      similar_location?(anOther, @similarity) &&
      similar_size?(anOther, @similarity)     &&
      same_style?(anOther)                    &&
      same_visibility?(anOther)
end
same_class?(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 90
def same_class?(anOther)
  @klass == anOther.klass
end
same_element?(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 30
def same_element?(anOther)
  same = same_tag?(anOther)   &&
         same_id?(anOther)    &&
         same_class?(anOther)
end
same_id?(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 94
def same_id?(anOther)
  @id == anOther.id
end
same_location?(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 82
def same_location?(anOther)
  (@left == anOther.left) && (@top == anOther.top)
end
same_size?(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 86
def same_size?(anOther)
  (@height == anOther.height) && (@width == anOther.width)
end
same_style?(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 102
def same_style?(anOther)
  @style == anOther.style
end
same_tag?(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 78
def same_tag?(anOther)
  @tag == anOther.tag
end
same_visibility?(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 98
def same_visibility?(anOther)
  @visible == anOther.visible
end
similar_height?(anOther, similarity = 0) click to toggle source
# File lib/dom_glancy/element.rb, line 74
def similar_height?(anOther, similarity = 0)
  (@height - anOther.height).abs <= similarity
end
similar_left?(anOther, similarity = 0) click to toggle source
# File lib/dom_glancy/element.rb, line 66
def similar_left?(anOther, similarity = 0)
  (@left - anOther.left).abs <= similarity
end
similar_location?(anOther, similarity = 0) click to toggle source
# File lib/dom_glancy/element.rb, line 57
def similar_location?(anOther, similarity = 0)
  similar = (@top - anOther.top).abs <= similarity
  similar && (@left - anOther.left).abs <= similarity
end
similar_size?(anOther, similarity = 0) click to toggle source
# File lib/dom_glancy/element.rb, line 52
def similar_size?(anOther, similarity = 0)
  similar = (@height - anOther.height).abs <= similarity
  similar && (@width - anOther.width).abs <= similarity
end
similar_top?(anOther, similarity = 0) click to toggle source
# File lib/dom_glancy/element.rb, line 62
def similar_top?(anOther, similarity = 0)
  (@top - anOther.top).abs <= similarity
end
similar_width?(anOther, similarity = 0) click to toggle source
# File lib/dom_glancy/element.rb, line 70
def similar_width?(anOther, similarity = 0)
  (@width - anOther.width).abs <= similarity
end
similarity_level(anOther) click to toggle source
# File lib/dom_glancy/element.rb, line 106
def similarity_level(anOther)
  level = 0
  if same_element?(anOther) && same_style?(anOther)
    level += 1 if similar_location?(anOther, @similarity) and !same_location?(anOther)
    level += 1 if similar_size?(anOther, @similarity)     and !same_size?(anOther)
  end
  level
end
to_hash() click to toggle source
# File lib/dom_glancy/element.rb, line 130
def to_hash
  {
      'id'      => @id,
      'height'  => @height,
      'visible' => @visible,
      'tag'     => @tag,
      'width'   => @width,
      'class'   => @klass,
      'left'    => @left,
      'top'     => @top
  }
end