Class: Moxml::Node

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(native_node = nil) ⇒ Node

Returns a new instance of Node.



5
6
7
# File 'lib/moxml/node.rb', line 5

def initialize(native_node = nil)
  @native = native_node || create_native_node
end

Instance Attribute Details

#nativeObject (readonly)

Returns the value of attribute native.



3
4
5
# File 'lib/moxml/node.rb', line 3

def native
  @native
end

Class Method Details

.wrap(native_node) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/moxml/node.rb', line 9

def self.wrap(native_node)
  return nil if native_node.nil?

  klass = case Moxml.adapter.node_type(native_node)
    when :element then Element
    when :text then Text
    when :cdata then Cdata
    when :comment then Comment
    when :processing_instruction then ProcessingInstruction
    when :document then Document
    when :attribute then Attribute
    when :namespace then Namespace
    else
      raise Error, "Unknown node type: #{native_node.class}"
    end

  klass.new(native_node)
end

Instance Method Details

#add_next_sibling(node) ⇒ Object



59
60
61
62
# File 'lib/moxml/node.rb', line 59

def add_next_sibling(node)
  adapter.add_next_sibling(native, node.native)
  self
end

#add_previous_sibling(node) ⇒ Object



54
55
56
57
# File 'lib/moxml/node.rb', line 54

def add_previous_sibling(node)
  adapter.add_previous_sibling(native, node.native)
  self
end

#childrenObject



32
33
34
# File 'lib/moxml/node.rb', line 32

def children
  NodeSet.new(adapter.children(native))
end

#columnObject



93
94
95
# File 'lib/moxml/node.rb', line 93

def column
  adapter.column(native)
end

#inner_htmlObject



73
74
75
# File 'lib/moxml/node.rb', line 73

def inner_html
  adapter.inner_html(native)
end

#inner_html=(html) ⇒ Object



77
78
79
# File 'lib/moxml/node.rb', line 77

def inner_html=(html)
  adapter.set_inner_html(native, html)
end

#lineObject



89
90
91
# File 'lib/moxml/node.rb', line 89

def line
  adapter.line(native)
end

#next_siblingObject



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

def next_sibling
  wrap_node(adapter.next_sibling(native))
end

#outer_htmlObject



81
82
83
# File 'lib/moxml/node.rb', line 81

def outer_html
  adapter.outer_html(native)
end

#parentObject



28
29
30
# File 'lib/moxml/node.rb', line 28

def parent
  wrap_node(adapter.parent(native))
end

#pathObject



85
86
87
# File 'lib/moxml/node.rb', line 85

def path
  adapter.path(native)
end

#previous_siblingObject



40
41
42
# File 'lib/moxml/node.rb', line 40

def previous_sibling
  wrap_node(adapter.previous_sibling(native))
end

#removeObject



44
45
46
47
# File 'lib/moxml/node.rb', line 44

def remove
  adapter.remove(native)
  self
end

#replace(node) ⇒ Object



49
50
51
52
# File 'lib/moxml/node.rb', line 49

def replace(node)
  adapter.replace(native, node.native)
  self
end

#textObject



64
65
66
# File 'lib/moxml/node.rb', line 64

def text
  adapter.text_content(native)
end

#text=(content) ⇒ Object



68
69
70
71
# File 'lib/moxml/node.rb', line 68

def text=(content)
  adapter.set_text_content(native, content)
  self
end