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.



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

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

#elementsObject



21
22
23
# 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?Boolean

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

Returns:

  • (Boolean)


31
32
33
# 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) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/test_xml/nokogiri/node.rb', line 35

def placeholder?
  TestXml.placeholders_enabled? and (content =~ /^`.*`$/)
end