class Nokogiri::XML::Document
Monkey patches for Nokogiri::XML::Document
@see www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Document Nokogiri::XML::Document
Public Instance Methods
add_all_namespaces!()
click to toggle source
# File lib/kitchen/patches/nokogiri.rb, line 35 def add_all_namespaces! # Nokogiri by default only recognizes the namespaces on the root node. Collect all # namespaces and add them manually. return if @all_namespaces_added collect_namespaces.each do |namespace, url| prefix, name = namespace.split(':') next unless prefix == 'xmlns' && name.present? root.add_namespace_definition(name, url) end @all_namespaces_added = true end
alphabetize_attributes!()
click to toggle source
Alphabetizes all attributes within the document, useful for comparing one document to another (since attribute order isn't meaningful)
# File lib/kitchen/patches/nokogiri.rb, line 19 def alphabetize_attributes! traverse do |child| next if child.text? || child.document? child_attributes = child.attributes child_attributes.each do |key, _value| child.remove_attribute(key) end sorted_keys = child_attributes.keys.sort sorted_keys.each do |key| value = child_attributes[key].to_s child[key] = value end end end
inspect()
click to toggle source
Hides the guts of the document when printed out so you don't get 5MB dumped into your terminal
# File lib/kitchen/patches/nokogiri.rb, line 12 def inspect 'Nokogiri::XML::Document <hidden for brevity>' end