Module: XmlSpec::NokogiriExt::Node
- Included in:
- Nokogiri::XML::Node
- Defined in:
- lib/xml_spec/nokogiri/node.rb
Instance Method Summary collapse
-
#comparable_attributes ⇒ Object
Attributes of the current node.
- #elements ⇒ Object
-
#leaf? ⇒ Boolean
Check if node is either childless, self-closing, or has content text.
- #match?(element, compare_value = false) ⇒ Boolean
Instance Method Details
#comparable_attributes ⇒ Object
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 |
#elements ⇒ Object
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.
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
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 |