Class: Moxml::DocumentBuilder
- Inherits:
-
Object
- Object
- Moxml::DocumentBuilder
- Defined in:
- lib/moxml/document_builder.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #build(native_doc) ⇒ Object
-
#initialize(context) ⇒ DocumentBuilder
constructor
A new instance of DocumentBuilder.
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
#context ⇒ Object (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 28 29 30 31 32 33 |
# File 'lib/moxml/document_builder.rb', line 12 def build(native_doc) @current_doc = context.create_document(native_doc) # Transfer has_declaration flag if present in attachments if adapter.respond_to?(:attachments) && adapter..key?(native_doc, :has_declaration) has_declaration = adapter..get(native_doc, :has_declaration) @current_doc.has_xml_declaration = has_declaration end # Transfer DOCTYPE from parsed document if it exists in attachments if adapter.respond_to?(:attachments) && adapter..key?(native_doc, :doctype) doctype = adapter..get(native_doc, :doctype) if doctype adapter..set(@current_doc.native, :doctype, doctype) end end visit_node(native_doc) @current_doc end |