Class: Leptris::XML::DocumentFragment

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_ptrObject (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

#documentObject (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

#childrenObject



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

#nameObject



34
35
36
# File 'lib/leptris/xml/document_fragment.rb', line 34

def name
  "#document-fragment"
end