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 34 |
# 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 if native_doc.respond_to?(:instance_variable_get) && native_doc.instance_variable_defined?(:@moxml_has_declaration) has_declaration = native_doc.instance_variable_get(:@moxml_has_declaration) @current_doc.has_xml_declaration = has_declaration end # 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 |