Class: Spreadsheet::LibxmlXmlBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/spreadsheet/libxml_xml_builder.rb

Instance Method Summary collapse

Constructor Details

#initializeLibxmlXmlBuilder

Returns a new instance of LibxmlXmlBuilder.



6
7
8
9
# File 'lib/spreadsheet/libxml_xml_builder.rb', line 6

def initialize
  @document = LibXML::XML::Document.new
  @node = nil
end

Instance Method Details

#import!(builder) ⇒ Object



28
29
30
# File 'lib/spreadsheet/libxml_xml_builder.rb', line 28

def import!(builder)
  @node << @document.import(builder.root)
end

#tag!(name, attrs = {}, content = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spreadsheet/libxml_xml_builder.rb', line 11

def tag!(name, attrs={}, content=nil)
  node = LibXML::XML::Node.new(name.to_s)
  node << content.to_s if content
  attrs.each { |k, v| LibXML::XML::Attr.new(node, k.to_s, v.to_s) }
  if @document.root
    @node << node
  else
    @node = node
    @document.root = node
  end
  if block_given?
    node, @node = @node, node
    yield
    @node = node
  end
end

#to_sObject



32
33
34
# File 'lib/spreadsheet/libxml_xml_builder.rb', line 32

def to_s
  @document.to_s
end