Class: Locator::Dom::Nokogiri::Element
- Defined in:
- lib/locator/dom/nokogiri/element.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #ancestor_of?(other) ⇒ Boolean
- #ancestors ⇒ Object
- #attribute(name) ⇒ Object
- #checked ⇒ Object
- #content ⇒ Object
- #css_path ⇒ Object
- #element_by_css(rule) ⇒ Object
- #element_by_id(id) ⇒ Object
- #element_by_xpath(xpath) ⇒ Object
- #elements_by_css(*rules) ⇒ Object
- #elements_by_xpath(*xpaths) ⇒ Object
-
#initialize(element) ⇒ Element
constructor
A new instance of Element.
- #inner_html ⇒ Object
- #name ⇒ Object
- #to_s ⇒ Object
- #value ⇒ Object
- #xpath ⇒ Object
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
#element ⇒ Object (readonly)
Returns the value of attribute element.
5 6 7 |
# File 'lib/locator/dom/nokogiri/element.rb', line 5 def element @element end |
#matches ⇒ Object (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
84 85 86 |
# File 'lib/locator/dom/nokogiri/element.rb', line 84 def ancestor_of?(other) other.ancestors.include?(element) end |
#ancestors ⇒ Object
80 81 82 |
# File 'lib/locator/dom/nokogiri/element.rb', line 80 def ancestors element.ancestors end |
#attribute(name) ⇒ Object
56 57 58 |
# File 'lib/locator/dom/nokogiri/element.rb', line 56 def attribute(name) element.attribute(name).to_s end |
#checked ⇒ Object
39 40 41 42 |
# File 'lib/locator/dom/nokogiri/element.rb', line 39 def checked checked = element.attribute('checked') checked ? checked.value : nil end |
#content ⇒ Object
44 45 46 |
# File 'lib/locator/dom/nokogiri/element.rb', line 44 def content element.content end |
#css_path ⇒ Object
24 25 26 |
# File 'lib/locator/dom/nokogiri/element.rb', line 24 def css_path element.css_path.to_s end |
#element_by_css(rule) ⇒ Object
72 73 74 |
# File 'lib/locator/dom/nokogiri/element.rb', line 72 def element_by_css(rule) elements_by_css(rule).first end |
#element_by_id(id) ⇒ Object
60 61 62 |
# File 'lib/locator/dom/nokogiri/element.rb', line 60 def element_by_id(id) elements_by_xpath("//*[@id='#{id}']").first end |
#element_by_xpath(xpath) ⇒ Object
64 65 66 |
# File 'lib/locator/dom/nokogiri/element.rb', line 64 def element_by_xpath(xpath) elements_by_xpath(xpath).first end |
#elements_by_css(*rules) ⇒ Object
76 77 78 |
# File 'lib/locator/dom/nokogiri/element.rb', line 76 def elements_by_css(*rules) element.css(*rules).map { |element| Element.new(element) } end |
#elements_by_xpath(*xpaths) ⇒ Object
68 69 70 |
# File 'lib/locator/dom/nokogiri/element.rb', line 68 def elements_by_xpath(*xpaths) element.xpath(*xpaths).map { |element| Element.new(element) } end |
#inner_html ⇒ Object
48 49 50 |
# File 'lib/locator/dom/nokogiri/element.rb', line 48 def inner_html element.inner_html end |
#name ⇒ Object
16 17 18 |
# File 'lib/locator/dom/nokogiri/element.rb', line 16 def name element.name end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/locator/dom/nokogiri/element.rb', line 52 def to_s element.to_s end |
#value ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/locator/dom/nokogiri/element.rb', line 28 def value case name when 'input' element.attribute('value').value when 'select' selected = element.children.select { |option| option.attribute('selected') } values = selected.map { |option| option.attribute('value') || option.content } element.attribute('multiple') ? values.strip : values.first.strip end end |
#xpath ⇒ Object
20 21 22 |
# File 'lib/locator/dom/nokogiri/element.rb', line 20 def xpath element.path.to_s end |