Class: Leptris::XML::DocumentFragment
- Inherits:
-
Object
- Object
- Leptris::XML::DocumentFragment
- Includes:
- Searchable
- 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
Methods included from Searchable
#at, #at_css, #at_xpath, #css, #search, wrap_xpath_first_result, wrap_xpath_result, #xpath
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 |
# File 'lib/leptris/xml/document_fragment.rb', line 17 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
27 28 29 30 31 32 |
# File 'lib/leptris/xml/document_fragment.rb', line 27 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
34 35 36 |
# File 'lib/leptris/xml/document_fragment.rb', line 34 def name "#document-fragment" end |