Module: TestXml::NokogiriExt::Node

Included in:
Nokogiri::XML::Node
Defined in:
lib/test_xml/nokogiri/node.rb

Instance Method Summary collapse

Instance Method Details

#comparable_attributesObject

Attributes of the current node.



18
19
20
# File 'lib/test_xml/nokogiri/node.rb', line 18

def comparable_attributes
  attributes.collect {|k,a| [k.downcase, a.value]}.sort
end

#elementsObject



13
14
15
# File 'lib/test_xml/nokogiri/node.rb', line 13

def elements
  children.collect {|node| node if node.element? }.delete_if {|node| node.nil?}
end

#leaf?Boolean

Check if node is either childless, self-closing, or has content text.

Returns:

  • (Boolean)


23
24
25
# File 'lib/test_xml/nokogiri/node.rb', line 23

def leaf?
  children.size == 0 or (children.size == 1 && children.first.text?)
end

#match?(element, compare_value = false) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
# File 'lib/test_xml/nokogiri/node.rb', line 4

def match?(element, compare_value = false)
  if compare_value && element.leaf?
    comparable_attributes == element.comparable_attributes and equal_text?(element)
  else
    contains_elements_of?(element) &&
    element.elements.all? {|el| matches_at_least_one?(el, compare_value) }
  end
end