Class: Kracker::DOMElement

Inherits:
Object
  • Object
show all
Defined in:
lib/kracker/element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#heightObject

Returns the value of attribute height.



11
12
13
# File 'lib/kracker/element.rb', line 11

def height
  @height
end

#idObject

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

#klassObject

Returns the value of attribute klass.



13
14
15
# File 'lib/kracker/element.rb', line 13

def klass
  @klass
end

#leftObject

Returns the value of attribute left.



9
10
11
# File 'lib/kracker/element.rb', line 9

def left
  @left
end

#similarityObject

Returns the value of attribute similarity.



16
17
18
# File 'lib/kracker/element.rb', line 16

def similarity
  @similarity
end

#styleObject

Returns the value of attribute style.



15
16
17
# File 'lib/kracker/element.rb', line 15

def style
  @style
end

#tagObject

Returns the value of attribute tag.



8
9
10
# File 'lib/kracker/element.rb', line 8

def tag
  @tag
end

#topObject

Returns the value of attribute top.



10
11
12
# File 'lib/kracker/element.rb', line 10

def top
  @top
end

#visibleObject

Returns the value of attribute visible.



14
15
16
# File 'lib/kracker/element.rb', line 14

def visible
  @visible
end

#widthObject

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


75
76
77
# File 'lib/kracker/element.rb', line 75

def same_class?(anOther)
  @klass == anOther.klass
end

#same_element?(anOther) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


79
80
81
# File 'lib/kracker/element.rb', line 79

def same_id?(anOther)
  @id == anOther.id
end

#same_location?(anOther) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


87
88
89
# File 'lib/kracker/element.rb', line 87

def same_style?(anOther)
  @style == anOther.style
end

#same_tag?(anOther) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/kracker/element.rb', line 63

def same_tag?(anOther)
  @tag == anOther.tag
end

#same_visibility?(anOther) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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