Class: Taurus::XML::DocumentFragment
- Inherits:
-
Object
- Object
- Taurus::XML::DocumentFragment
- Defined in:
- lib/taurus/xml/document_fragment.rb
Overview
Wraps the synthetic "#document-fragment" element returned by taurus_parse_fragment. Children of this fragment are the parsed nodes; the fragment itself isn't part of any document tree but borrows its document's lifetime.
Instance Attribute Summary collapse
-
#c_ptr ⇒ Object
readonly
Returns the value of attribute c_ptr.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Class Method Summary collapse
Instance Method Summary collapse
- #children ⇒ Object
-
#initialize(document, c_ptr) ⇒ DocumentFragment
constructor
A new instance of DocumentFragment.
- #name ⇒ Object
Constructor Details
#initialize(document, c_ptr) ⇒ DocumentFragment
Returns a new instance of DocumentFragment.
12 13 14 15 |
# File 'lib/taurus/xml/document_fragment.rb', line 12 def initialize(document, c_ptr) @document = document @c_ptr = c_ptr end |
Instance Attribute Details
#c_ptr ⇒ Object (readonly)
Returns the value of attribute c_ptr.
10 11 12 |
# File 'lib/taurus/xml/document_fragment.rb', line 10 def c_ptr @c_ptr end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
10 11 12 |
# File 'lib/taurus/xml/document_fragment.rb', line 10 def document @document end |
Class Method Details
.parse(xml, document) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/taurus/xml/document_fragment.rb', line 17 def self.parse(xml, document) status_ptr = ::FFI::MemoryPointer.new(:int) raw = Taurus::XML::FFI.taurus_parse_fragment( xml.to_s, xml.to_s.bytesize, document.c_ptr, status_ptr) if raw.null? raise Taurus::XML::ParseError, "taurus_parse_fragment failed (status=#{status_ptr.read_int})" end new(document, raw) end |
Instance Method Details
#children ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/taurus/xml/document_fragment.rb', line 28 def children count = Taurus::XML::FFI.taurus_element_child_count(@c_ptr) nodes = [] ptr = Taurus::XML::FFI.taurus_node_first_child(@c_ptr) until ptr.nil? || ptr.null? nodes << Taurus::XML::Node.wrap(ptr, @document) ptr = Taurus::XML::FFI.taurus_node_next_sibling(ptr) end Taurus::XML::NodeSet.new(@document, nodes) end |
#name ⇒ Object
39 40 41 |
# File 'lib/taurus/xml/document_fragment.rb', line 39 def name "#document-fragment" end |