Class: Moxml::Adapter::CustomizedLibxml::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/moxml/adapter/customized_libxml/node.rb

Overview

Base wrapper class for LibXML nodes

This wrapper hides LibXML’s strict document ownership model, allowing nodes to be moved between documents transparently. Similar pattern to Ox adapter’s customized classes.

The Libxml adapter owns wrapper type mapping in one place so the wrapper classes do not duplicate node-type knowledge.

Direct Known Subclasses

Cdata, Comment, Element, ProcessingInstruction, Text

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(native_node) ⇒ Node

Returns a new instance of Node.



17
18
19
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 17

def initialize(native_node)
  @native = native_node
end

Instance Attribute Details

#nativeObject (readonly)

Returns the value of attribute native.



15
16
17
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 15

def native
  @native
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Compare wrappers based on their native nodes



22
23
24
25
26
27
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 22

def ==(other)
  return false unless other

  other_native = other.respond_to?(:native) ? other.native : other
  @native == other_native
end

#documentObject

Get the document this node belongs to



41
42
43
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 41

def document
  @native.doc if document_present?
end

#document_present?Boolean

Check if node has a document

Returns:

  • (Boolean)


36
37
38
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 36

def document_present?
  @native.respond_to?(:doc) && !@native.doc.nil?
end

#hashObject



31
32
33
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 31

def hash
  @native.hash
end