Class: DomGlancy::DOMElement
- Inherits:
-
Object
- Object
- DomGlancy::DOMElement
- Defined in:
- lib/dom_glancy/element.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
element looks like this in archive.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#left ⇒ Object
Returns the value of attribute left.
-
#similarity ⇒ Object
Returns the value of attribute similarity.
-
#style ⇒ Object
Returns the value of attribute style.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#top ⇒ Object
Returns the value of attribute top.
-
#visible ⇒ Object
Returns the value of attribute visible.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #all_same?(anOther) ⇒ Boolean
- #change_info(anOther) ⇒ Object
- #change_level(anOther) ⇒ Object
- #close_enough?(anOther) ⇒ Boolean
-
#initialize(h = {}) ⇒ DOMElement
constructor
A new instance of DOMElement.
- #same_class?(anOther) ⇒ Boolean
- #same_element?(anOther) ⇒ Boolean
- #same_id?(anOther) ⇒ Boolean
- #same_location?(anOther) ⇒ Boolean
- #same_size?(anOther) ⇒ Boolean
- #same_style?(anOther) ⇒ Boolean
- #same_tag?(anOther) ⇒ Boolean
- #same_visibility?(anOther) ⇒ Boolean
- #similar_height?(anOther, similarity = 0) ⇒ Boolean
- #similar_left?(anOther, similarity = 0) ⇒ Boolean
- #similar_location?(anOther, similarity = 0) ⇒ Boolean
- #similar_size?(anOther, similarity = 0) ⇒ Boolean
- #similar_top?(anOther, similarity = 0) ⇒ Boolean
- #similar_width?(anOther, similarity = 0) ⇒ Boolean
- #similarity_level(anOther) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(h = {}) ⇒ DOMElement
Returns a new instance of DOMElement.
17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
10 11 12 |
# File 'lib/dom_glancy/element.rb', line 10 def height @height end |
#id ⇒ Object
element looks like this in archive. “height”=>238, “visible”=>true, “tag”=>“DIV”, “width”=>720, “class”=>“grid”, “left”=>43, “top”=>14
6 7 8 |
# File 'lib/dom_glancy/element.rb', line 6 def id @id end |
#klass ⇒ Object
Returns the value of attribute klass.
12 13 14 |
# File 'lib/dom_glancy/element.rb', line 12 def klass @klass end |
#left ⇒ Object
Returns the value of attribute left.
8 9 10 |
# File 'lib/dom_glancy/element.rb', line 8 def left @left end |
#similarity ⇒ Object
Returns the value of attribute similarity.
15 16 17 |
# File 'lib/dom_glancy/element.rb', line 15 def similarity @similarity end |
#style ⇒ Object
Returns the value of attribute style.
14 15 16 |
# File 'lib/dom_glancy/element.rb', line 14 def style @style end |
#tag ⇒ Object
Returns the value of attribute tag.
7 8 9 |
# File 'lib/dom_glancy/element.rb', line 7 def tag @tag end |
#top ⇒ Object
Returns the value of attribute top.
9 10 11 |
# File 'lib/dom_glancy/element.rb', line 9 def top @top end |
#visible ⇒ Object
Returns the value of attribute visible.
13 14 15 |
# File 'lib/dom_glancy/element.rb', line 13 def visible @visible end |
#width ⇒ Object
Returns the value of attribute width.
11 12 13 |
# File 'lib/dom_glancy/element.rb', line 11 def width @width end |
Instance Method Details
#all_same?(anOther) ⇒ Boolean
36 37 38 39 40 41 42 |
# 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) ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# 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) ⇒ Object
115 116 117 |
# File 'lib/dom_glancy/element.rb', line 115 def change_level(anOther) change_info(anOther).length end |
#close_enough?(anOther) ⇒ Boolean
44 45 46 47 48 49 50 |
# 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) ⇒ Boolean
90 91 92 |
# File 'lib/dom_glancy/element.rb', line 90 def same_class?(anOther) @klass == anOther.klass end |
#same_element?(anOther) ⇒ Boolean
30 31 32 33 34 |
# 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) ⇒ Boolean
94 95 96 |
# File 'lib/dom_glancy/element.rb', line 94 def same_id?(anOther) @id == anOther.id end |
#same_location?(anOther) ⇒ Boolean
82 83 84 |
# File 'lib/dom_glancy/element.rb', line 82 def same_location?(anOther) (@left == anOther.left) && (@top == anOther.top) end |
#same_size?(anOther) ⇒ Boolean
86 87 88 |
# File 'lib/dom_glancy/element.rb', line 86 def same_size?(anOther) (@height == anOther.height) && (@width == anOther.width) end |
#same_style?(anOther) ⇒ Boolean
102 103 104 |
# File 'lib/dom_glancy/element.rb', line 102 def same_style?(anOther) @style == anOther.style end |
#same_tag?(anOther) ⇒ Boolean
78 79 80 |
# File 'lib/dom_glancy/element.rb', line 78 def same_tag?(anOther) @tag == anOther.tag end |
#same_visibility?(anOther) ⇒ Boolean
98 99 100 |
# File 'lib/dom_glancy/element.rb', line 98 def same_visibility?(anOther) @visible == anOther.visible end |
#similar_height?(anOther, similarity = 0) ⇒ Boolean
74 75 76 |
# 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) ⇒ Boolean
66 67 68 |
# 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) ⇒ Boolean
57 58 59 60 |
# 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) ⇒ Boolean
52 53 54 55 |
# 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) ⇒ Boolean
62 63 64 |
# 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) ⇒ Boolean
70 71 72 |
# File 'lib/dom_glancy/element.rb', line 70 def similar_width?(anOther, similarity = 0) (@width - anOther.width).abs <= similarity end |
#similarity_level(anOther) ⇒ Object
106 107 108 109 110 111 112 113 |
# 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 ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 |
# 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 |