Class: Moxml::DocumentBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/moxml/document_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ DocumentBuilder

Returns a new instance of DocumentBuilder.



7
8
9
10
# File 'lib/moxml/document_builder.rb', line 7

def initialize(context)
  @context = context
  @node_stack = []
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/moxml/document_builder.rb', line 5

def context
  @context
end

Instance Method Details

#build(native_doc) ⇒ Object



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

def build(native_doc)
  @current_doc = context.create_document(native_doc)

  # Transfer DOCTYPE from parsed document if it exists
  if native_doc.respond_to?(:instance_variable_get) &&
      native_doc.instance_variable_defined?(:@moxml_doctype)
    doctype = native_doc.instance_variable_get(:@moxml_doctype)
    if doctype
      @current_doc.native.instance_variable_set(:@moxml_doctype,
                                                doctype)
    end
  end

  visit_node(native_doc)
  @current_doc
end