module TestXml::NokogiriExt::Node

Public Instance Methods

comparable_attributes() click to toggle source

Attributes of the current node.

# File lib/test_xml/nokogiri/node.rb, line 26
def comparable_attributes
  attributes.collect {|k,a| [k.downcase, a.value]}.sort
end
elements() click to toggle source
# File lib/test_xml/nokogiri/node.rb, line 21
def elements
  children.collect {|node| node if node.element? }.delete_if {|node| node.nil?}
end
leaf?() click to toggle source

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

# File lib/test_xml/nokogiri/node.rb, line 31
def leaf?
  children.size == 0 or (children.size == 1 && children.first.text?)
end
match?(element, compare_value = false) click to toggle source
# 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

    #TODO clean this part of the code
    if compare_value
      (comparable_attributes == element.comparable_attributes) &&
      contains_elements_of?(element) &&
      element.elements.all? {|el| matches_at_least_one?(el, compare_value) }
    else
      contains_elements_of?(element) &&
      element.elements.all? {|el| matches_at_least_one?(el, compare_value) }
    end
  end
end
placeholder?() click to toggle source
# File lib/test_xml/nokogiri/node.rb, line 35
def placeholder?
  TestXml.placeholders_enabled? and (content =~ /^`.*`$/)
end

Private Instance Methods

contains?(element) click to toggle source
# File lib/test_xml/nokogiri/node.rb, line 51
def contains?(element)
  children.find {|node| node.element? && node.name == element.name }
end
contains_elements_of?(element) click to toggle source
# File lib/test_xml/nokogiri/node.rb, line 47
def contains_elements_of?(element)
  element.elements.find {|el| not contains?(el)}.nil?
end
equal_text?(element) click to toggle source
# File lib/test_xml/nokogiri/node.rb, line 40
def equal_text?(element)
  element.content = content if element.placeholder?

  content == element.content
end
matches_at_least_one?(element, compare_value) click to toggle source
# File lib/test_xml/nokogiri/node.rb, line 55
def matches_at_least_one?(element, compare_value)
  search(element.name).find { |el| el.match?(element, compare_value) }
end