Class: Kracker::DOMElement
- Inherits:
-
Object
- Object
- Kracker::DOMElement
- Defined in:
- lib/kracker/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
- #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_location?(anOther, similarity = 0) ⇒ Boolean
- #similar_size?(anOther, similarity = 0) ⇒ Boolean
Constructor Details
#initialize(h = {}) ⇒ DOMElement
Returns a new instance of DOMElement.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kracker/element.rb', line 18 def initialize(h = {}) @tag = h[:tag] || h['tag'] @left = h[:left] || h['left'] @top = h[:top] || h['top'] @height = h[:height] || h['height'] @width = h[:width] || h['width'] @klass = h[:class] || h['class'] @id = h[:id] || h['id'] @style = h[:style] || h['style'] @visible = h[:visible] || h['visible'] @similarity = h[:similarity] || h['similarity'] || 15 end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
11 12 13 |
# File 'lib/kracker/element.rb', line 11 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
7 8 9 |
# File 'lib/kracker/element.rb', line 7 def id @id end |
#klass ⇒ Object
Returns the value of attribute klass.
13 14 15 |
# File 'lib/kracker/element.rb', line 13 def klass @klass end |
#left ⇒ Object
Returns the value of attribute left.
9 10 11 |
# File 'lib/kracker/element.rb', line 9 def left @left end |
#similarity ⇒ Object
Returns the value of attribute similarity.
16 17 18 |
# File 'lib/kracker/element.rb', line 16 def similarity @similarity end |
#style ⇒ Object
Returns the value of attribute style.
15 16 17 |
# File 'lib/kracker/element.rb', line 15 def style @style end |
#tag ⇒ Object
Returns the value of attribute tag.
8 9 10 |
# File 'lib/kracker/element.rb', line 8 def tag @tag end |
#top ⇒ Object
Returns the value of attribute top.
10 11 12 |
# File 'lib/kracker/element.rb', line 10 def top @top end |
#visible ⇒ Object
Returns the value of attribute visible.
14 15 16 |
# File 'lib/kracker/element.rb', line 14 def visible @visible end |
#width ⇒ Object
Returns the value of attribute width.
12 13 14 |
# File 'lib/kracker/element.rb', line 12 def width @width end |
Instance Method Details
#all_same?(anOther) ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/kracker/element.rb', line 37 def all_same?(anOther) same = same_element?(anOther) && similar_size?(anOther, 0) && similar_location?(anOther, 0) && same_size?(anOther) && same_visibility?(anOther) end |
#close_enough?(anOther) ⇒ Boolean
45 46 47 48 49 50 51 |
# File 'lib/kracker/element.rb', line 45 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
75 76 77 |
# File 'lib/kracker/element.rb', line 75 def same_class?(anOther) @klass == anOther.klass end |
#same_element?(anOther) ⇒ Boolean
31 32 33 34 35 |
# File 'lib/kracker/element.rb', line 31 def same_element?(anOther) same = same_tag?(anOther) && same_id?(anOther) && same_class?(anOther) end |
#same_id?(anOther) ⇒ Boolean
79 80 81 |
# File 'lib/kracker/element.rb', line 79 def same_id?(anOther) @id == anOther.id end |
#same_location?(anOther) ⇒ Boolean
67 68 69 |
# File 'lib/kracker/element.rb', line 67 def same_location?(anOther) (@left == anOther.left) && (@top == anOther.top) end |
#same_size?(anOther) ⇒ Boolean
71 72 73 |
# File 'lib/kracker/element.rb', line 71 def same_size?(anOther) (@height == anOther.height) && (@width == anOther.width) end |
#same_style?(anOther) ⇒ Boolean
87 88 89 |
# File 'lib/kracker/element.rb', line 87 def same_style?(anOther) @style == anOther.style end |
#same_tag?(anOther) ⇒ Boolean
63 64 65 |
# File 'lib/kracker/element.rb', line 63 def same_tag?(anOther) @tag == anOther.tag end |
#same_visibility?(anOther) ⇒ Boolean
83 84 85 |
# File 'lib/kracker/element.rb', line 83 def same_visibility?(anOther) @visible == anOther.visible end |
#similar_location?(anOther, similarity = 0) ⇒ Boolean
58 59 60 61 |
# File 'lib/kracker/element.rb', line 58 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
53 54 55 56 |
# File 'lib/kracker/element.rb', line 53 def similar_size?(anOther, similarity = 0) similar = (@height - anOther.height).abs <= similarity similar && (@width - anOther.width).abs <= similarity end |