Class: Locator::Dom::Nokogiri::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/locator/dom/nokogiri/element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ Element

Returns a new instance of Element.



7
8
9
10
# File 'lib/locator/dom/nokogiri/element.rb', line 7

def initialize(element)
  @element = element
  @matches = []
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



5
6
7
# File 'lib/locator/dom/nokogiri/element.rb', line 5

def element
  @element
end

#matchesObject (readonly)

Returns the value of attribute matches.



5
6
7
# File 'lib/locator/dom/nokogiri/element.rb', line 5

def matches
  @matches
end

Instance Method Details

#<=>(other) ⇒ Object



12
13
14
# File 'lib/locator/dom/nokogiri/element.rb', line 12

def <=>(other)
  to_s.length <=> other.to_s.length
end

#ancestor_of?(other) ⇒ Boolean

Returns:



64
65
66
# File 'lib/locator/dom/nokogiri/element.rb', line 64

def ancestor_of?(other)
  other.ancestors.include?(element)
end

#ancestorsObject



60
61
62
# File 'lib/locator/dom/nokogiri/element.rb', line 60

def ancestors
  element.ancestors
end

#attribute(name) ⇒ Object



40
41
42
# File 'lib/locator/dom/nokogiri/element.rb', line 40

def attribute(name)
  element.attribute(name).to_s
end

#contentObject



28
29
30
# File 'lib/locator/dom/nokogiri/element.rb', line 28

def content
  element.content
end

#css_pathObject



24
25
26
# File 'lib/locator/dom/nokogiri/element.rb', line 24

def css_path
  element.css_path.to_s
end

#element_by_id(id) ⇒ Object



44
45
46
# File 'lib/locator/dom/nokogiri/element.rb', line 44

def element_by_id(id)
  elements_by_xpath("//*[@id='#{id}']").first
end

#element_by_xpath(xpath) ⇒ Object



48
49
50
# File 'lib/locator/dom/nokogiri/element.rb', line 48

def element_by_xpath(xpath)
  elements_by_xpath(xpath).first
end

#elements_by_css(*rules) ⇒ Object



56
57
58
# File 'lib/locator/dom/nokogiri/element.rb', line 56

def elements_by_css(*rules)
  element.css(*rules).map { |element| Element.new(element) }
end

#elements_by_xpath(*xpaths) ⇒ Object



52
53
54
# File 'lib/locator/dom/nokogiri/element.rb', line 52

def elements_by_xpath(*xpaths)
  element.xpath(*xpaths).map { |element| Element.new(element) }
end

#inner_htmlObject



32
33
34
# File 'lib/locator/dom/nokogiri/element.rb', line 32

def inner_html
  element.inner_html
end

#nameObject



16
17
18
# File 'lib/locator/dom/nokogiri/element.rb', line 16

def name
  element.name
end

#to_sObject



36
37
38
# File 'lib/locator/dom/nokogiri/element.rb', line 36

def to_s
  element.to_s
end

#xpathObject



20
21
22
# File 'lib/locator/dom/nokogiri/element.rb', line 20

def xpath
  element.path.to_s
end