Module: XmlSpec::NokogiriExt::Node

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

Instance Method Summary collapse

Instance Method Details

#comparable_attributesObject

Attributes of the current node.



26
27
28
# File 'lib/xml_spec/nokogiri/node.rb', line 26

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

#elementsObject



21
22
23
# File 'lib/xml_spec/nokogiri/node.rb', line 21

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)


31
32
33
# File 'lib/xml_spec/nokogiri/node.rb', line 31

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
12
13
14
15
16
17
18
19
# File 'lib/xml_spec/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