Class: Leptris::XML::DocumentFragment
- Inherits:
-
Object
- Object
- Leptris::XML::DocumentFragment
- Defined in:
- lib/leptris/xml/document_fragment.rb
Overview
Wraps the synthetic "#document-fragment" element returned by leptris_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/leptris/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/leptris/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/leptris/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/leptris/xml/document_fragment.rb', line 17 def self.parse(xml, document) status_ptr = ::FFI::MemoryPointer.new(:int) raw = Leptris::XML::FFI.leptris_parse_fragment( xml.to_s, xml.to_s.bytesize, document.c_ptr, status_ptr) if raw.null? raise Leptris::XML::ParseError, "leptris_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/leptris/xml/document_fragment.rb', line 28 def children count = Leptris::XML::FFI.leptris_element_child_count(@c_ptr) nodes = [] ptr = Leptris::XML::FFI.leptris_node_first_child(@c_ptr) until ptr.nil? || ptr.null? nodes << Leptris::XML::Node.wrap(ptr, @document) ptr = Leptris::XML::FFI.leptris_node_next_sibling(ptr) end Leptris::XML::NodeSet.new(@document, nodes) end |
#name ⇒ Object
39 40 41 |
# File 'lib/leptris/xml/document_fragment.rb', line 39 def name "#document-fragment" end |