Class: LLT::XmlHandler::PreProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/llt/xml_handler/pre_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, root: nil, ns: nil) ⇒ PreProcessor

Returns a new instance of PreProcessor.



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

def initialize(document, root: nil, ns: nil)
  @document = Nokogiri::XML(document)
  @namespace = ns
  go_to_root(root) if root

  @document.encoding = "UTF-8"
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



6
7
8
# File 'lib/llt/xml_handler/pre_processor.rb', line 6

def document
  @document
end

Instance Method Details

#remove_nodes(*nodes) ⇒ Object



20
21
22
23
24
# File 'lib/llt/xml_handler/pre_processor.rb', line 20

def remove_nodes(*nodes)
  nodes.each do |node|
    @document.xpath(*to_xpath(node, @namespace)).each(&:remove)
  end
end

#to_xmlObject



16
17
18
# File 'lib/llt/xml_handler/pre_processor.rb', line 16

def to_xml
  without_duplicate_declaration(@document.to_xml).strip
end