Class: Nokolexbor::DocumentFragment

Inherits:
Node
  • Object
show all
Defined in:
lib/nokolexbor/document_fragment.rb

Constant Summary

Constants inherited from Node

Node::ATTRIBUTE_NODE, Node::CDATA_SECTION_NODE, Node::COMMENT_NODE, Node::DOCUMENT_FRAG_NODE, Node::DOCUMENT_NODE, Node::DOCUMENT_TYPE_NODE, Node::ELEMENT_NODE, Node::ENTITY_NODE, Node::ENTITY_REF_NODE, Node::LOOKS_LIKE_XPATH, Node::NOTATION_NODE, Node::PI_NODE, Node::TEXT_NODE

Instance Attribute Summary

Attributes inherited from Node

#document

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#<<, #add_class, #add_next_sibling, #add_previous_sibling, #after, #ancestors, #append_class, #at, #at_css, #at_xpath, #attributes, #before, #cdata?, #children=, #classes, #comment?, #css, #css_path, #document?, #each, #element?, #fragment?, #kwattr_add, #kwattr_append, #kwattr_remove, #kwattr_values, #matches?, #nokogiri_at_css, #nokogiri_css, #parent=, #prepend_child, #processing_instruction?, #remove_class, #replace, #search, #swap, #text?, #traverse, #value?, #wrap, #write_to, #xpath

Constructor Details

#initialize(document, tags = nil, ctx = nil) ⇒ DocumentFragment

Create a new Nokolexbor::DocumentFragment from tags.

If +ctx+ is present, it is used as a context node for the
subtree created.


16
17
18
19
20
21
22
23
# File 'lib/nokolexbor/document_fragment.rb', line 16

def initialize(document, tags = nil, ctx = nil)
  return self unless tags

  ctx ||= document
  node_set = ctx.parse(tags)
  node_set.each { |child| child.parent = self } unless node_set.empty?
  nil
end

Class Method Details

.parse(tags) ⇒ DocumentFragment

Create a Nokolexbor::DocumentFragment from tags.

Returns:



8
9
10
# File 'lib/nokolexbor/document_fragment.rb', line 8

def self.parse(tags)
  new(Nokolexbor::Document.new, tags, nil)
end

Instance Method Details

#fragment(data) ⇒ DocumentFragment

Create a Nokolexbor::DocumentFragment from data.

Returns:



38
39
40
# File 'lib/nokolexbor/document_fragment.rb', line 38

def fragment(data)
  document.fragment(data)
end

#nameString

Returns The name of Nokolexbor::DocumentFragment.

Returns:



26
27
28
# File 'lib/nokolexbor/document_fragment.rb', line 26

def name
  "#document-fragment"
end