Module: Demolisher

Defined in:
lib/demolisher.rb

Defined Under Namespace

Classes: Node

Class Method Summary collapse

Class Method Details

._exchange_libxml(thing) ⇒ Object



16
17
18
19
# File 'lib/demolisher.rb', line 16

def self._exchange_libxml(thing)
  thing = thing.parse if thing.respond_to?(:parse)
  thing.to_s
end

._parse(thing) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/demolisher.rb', line 20

def self._parse(thing)
  if thing.kind_of?(LibXML::XML::Parser) || thing.kind_of?(LibXML::XML::Document)
    Nokogiri::XML::Document.parse(_exchange_libxml(thing))
  else
    # could be string data or a file name
    thing = File.open(thing) if File.exists?(thing)
    Nokogiri::XML::Document.parse(thing)
  end
end

.demolish(thing, namespaces = nil) {|node| ... } ⇒ Object

Demolish an XML file or XML::Parser object.

Parameters:

  • thing (String, IO, #parse)

Yields:

  • (node)


8
9
10
11
12
13
14
# File 'lib/demolisher.rb', line 8

def self.demolish(thing, namespaces = nil)
  thing = _parse(thing) unless thing.kind_of?(Nokogiri::XML::Document)
  node = Node.new(thing, namespaces, true)

  yield node if block_given?
  node
end