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.
10 11 12 13 |
# File 'lib/leptris/xml/document_fragment.rb', line 10 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.
8 9 10 |
# File 'lib/leptris/xml/document_fragment.rb', line 8 def c_ptr @c_ptr end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
8 9 10 |
# File 'lib/leptris/xml/document_fragment.rb', line 8 def document @document end |
Class Method Details
.parse(xml, document) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/leptris/xml/document_fragment.rb', line 15 def self.parse(xml, document) raw, status = Leptris::XML::FFI.parse_fragment_with_status( xml.to_s, document.c_ptr) if raw.null? raise Leptris::XML::ParseError, "leptris_parse_fragment failed (status=#{status})" end new(document, raw) end |
Instance Method Details
#children ⇒ Object
25 26 27 28 29 30 |
# File 'lib/leptris/xml/document_fragment.rb', line 25 def children nodes = Leptris::XML::FFI.fetch_children(@c_ptr).map do |ptr| Leptris::XML::Node.wrap(ptr, @document) end Leptris::XML::NodeSet.new(@document, nodes) end |
#name ⇒ Object
32 33 34 |
# File 'lib/leptris/xml/document_fragment.rb', line 32 def name "#document-fragment" end |