Module: Taka::DOM::Node

Defined in:
lib/taka/dom/node.rb

Constant Summary collapse

ELEMENT_NODE =
1
ATTRIBUTE_NODE =
2
TEXT_NODE =
3
CDATA_SECTION_NODE =
4
ENTITY_REF_NODE =
5
ENTITY_NODE =
6
PI_NODE =
7
COMMENT_NODE =
8
DOCUMENT_NODE =
9
DOCUMENT_TYPE_NODE =
10
DOCUMENT_FRAG_NODE =
11
NOTATION_NODE =
12
HTML_DOCUMENT_NODE =
13
DTD_NODE =
14
ELEMENT_DECL =
15
ATTRIBUTE_DECL =
16
ENTITY_DECL =
17
NAMESPACE_DECL =
18
XINCLUDE_START =
19
XINCLUDE_END =
20
DOCB_DOCUMENT_NODE =
21
DOCUMENT_POSITION_DISCONNECTED =
0
DOCUMENT_POSITION_PRECEDING =
0
DOCUMENT_POSITION_FOLLOWING =
0
DOCUMENT_POSITION_CONTAINS =
0
DOCUMENT_POSITION_CONTAINED_BY =
0
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC =
0

Instance Method Summary collapse

Instance Method Details

#appendChild(new_child) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/taka/dom/node.rb', line 176

def appendChild new_child
  unless can_append?(new_child)
    raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
  end

  if document != new_child.document
    raise DOMException.new(DOMException::WRONG_DOCUMENT_ERR)
  end

  if ancestors.include?(new_child)
    raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
  end
  add_child new_child
  new_child
end

#attributesObject



105
106
107
108
109
110
111
# File 'lib/taka/dom/node.rb', line 105

def attributes
  return nil unless attribute_nodes
  hash = super
  hash.extend(DOM::NamedNodeMap)
  hash.document = document
  hash
end

#baseURIObject

Raises:

  • (NotImplementedError)


238
239
240
# File 'lib/taka/dom/node.rb', line 238

def baseURI
  raise(NotImplementedError.new)
end

#can_append?(new_child) ⇒ Boolean

Returns true if new_child can be appended

Returns:

  • (Boolean)


288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/taka/dom/node.rb', line 288

def can_append? new_child
  return true if new_child.nodeType == DOCUMENT_FRAG_NODE
  return false if [
    DOCUMENT_TYPE_NODE,
    DTD_NODE,
    PI_NODE,
    COMMENT_NODE,
    TEXT_NODE,
    CDATA_SECTION_NODE,
    NOTATION_NODE
  ].include?(nodeType)

  if [
    DOCUMENT_FRAG_NODE,
    ENTITY_REF_NODE,
    ELEMENT_NODE,
    ENTITY_NODE,
    ENTITY_DECL
  ].include?(nodeType)
    return false unless [
      ELEMENT_NODE,
      PI_NODE,
      COMMENT_NODE,
      TEXT_NODE,
      CDATA_SECTION_NODE,
      ENTITY_REF_NODE
    ].include?(new_child.nodeType)
  end

  case nodeType
  when DOCUMENT_NODE
    return false unless [
      ELEMENT_NODE,
      PI_NODE,
      COMMENT_NODE,
      DTD_NODE,
      DOCUMENT_TYPE_NODE,
      ELEMENT_NODE,
    ].include?(new_child.nodeType)
  when ATTRIBUTE_NODE
    return false unless [
      TEXT_NODE,
      ENTITY_REF_NODE,
    ].include?(new_child.nodeType)
  end

  true
end

#childNodesObject



82
83
84
85
86
# File 'lib/taka/dom/node.rb', line 82

def childNodes
  DOM::NodeList.new do
    self.children
  end
end

#cloneNode(deep) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/taka/dom/node.rb', line 196

def cloneNode deep
  if [
    Node::ENTITY_NODE,
    Node::ENTITY_DECL,
    Node::NOTATION_NODE,
    Node::DOCUMENT_TYPE_NODE,
    Node::DTD_NODE,
    Node::NAMESPACE_DECL,
  ].include?(nodeType)
    raise DOMException.new(DOMException::NOT_SUPPORTED_ERR)
  end
  dup(deep ? 1 : 0)
end

#compareDocumentPosition(other) ⇒ Object

Raises:

  • (NotImplementedError)


248
249
250
# File 'lib/taka/dom/node.rb', line 248

def compareDocumentPosition(other)
  raise(NotImplementedError.new)
end

#firstChildObject



88
89
90
# File 'lib/taka/dom/node.rb', line 88

def firstChild
  children.first
end

#getFeature(feature, version) ⇒ Object

Raises:

  • (NotImplementedError)


276
277
278
# File 'lib/taka/dom/node.rb', line 276

def getFeature(feature, version)
  raise(NotImplementedError.new)
end

#getUserData(key) ⇒ Object

Raises:

  • (NotImplementedError)


282
283
284
# File 'lib/taka/dom/node.rb', line 282

def getUserData(key)
  raise(NotImplementedError.new)
end

#hasAttributesObject

Raises:

  • (NotImplementedError)


234
235
236
# File 'lib/taka/dom/node.rb', line 234

def hasAttributes
  raise(NotImplementedError.new)
end

#hasChildNodesObject



192
193
194
# File 'lib/taka/dom/node.rb', line 192

def hasChildNodes
  !children.empty?
end

#insertBefore(new_child, ref_child) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/taka/dom/node.rb', line 118

def insertBefore new_child, ref_child
  unless can_append?(new_child)
    raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
  end

  if read_only?
    raise DOMException.new(DOMException::NO_MODIFICATION_ALLOWED_ERR)
  end

  if ref_child && !children.include?(ref_child)
    raise DOMException.new(DOMException::NOT_FOUND_ERR)
  end

  if ancestors.include?(new_child)
    raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
  end

  if new_child.document != document
    raise DOMException.new(DOMException::WRONG_DOCUMENT_ERR)
  end

  unless ref_child
    new_child.parent = self
  else
    return ref_child.add_previous_sibling(new_child)
  end
  new_child
end

#isDefaultNamespace(namespaceURI) ⇒ Object

Raises:

  • (NotImplementedError)


267
268
269
# File 'lib/taka/dom/node.rb', line 267

def isDefaultNamespace(namespaceURI)
  raise(NotImplementedError.new)
end

#isEqualNode(arg) ⇒ Object

Raises:

  • (NotImplementedError)


273
274
275
# File 'lib/taka/dom/node.rb', line 273

def isEqualNode(arg)
  raise(NotImplementedError.new)
end

#isSameNode(other) ⇒ Object

Raises:

  • (NotImplementedError)


260
261
262
# File 'lib/taka/dom/node.rb', line 260

def isSameNode(other)
  raise(NotImplementedError.new)
end

#isSupported(feature, version) ⇒ Object

Raises:

  • (NotImplementedError)


214
215
216
# File 'lib/taka/dom/node.rb', line 214

def isSupported(feature, version)
  raise(NotImplementedError.new)
end

#lastChildObject



92
93
94
# File 'lib/taka/dom/node.rb', line 92

def lastChild
  children.last
end

#localNameObject

Raises:

  • (NotImplementedError)


230
231
232
# File 'lib/taka/dom/node.rb', line 230

def localName
  raise(NotImplementedError.new)
end

#lookupNamespaceURI(prefix) ⇒ Object

Raises:

  • (NotImplementedError)


270
271
272
# File 'lib/taka/dom/node.rb', line 270

def lookupNamespaceURI(prefix)
  raise(NotImplementedError.new)
end

#lookupPrefix(namespaceURI) ⇒ Object

Raises:

  • (NotImplementedError)


264
265
266
# File 'lib/taka/dom/node.rb', line 264

def lookupPrefix(namespaceURI)
  raise(NotImplementedError.new)
end

#namespaceURIObject

Raises:

  • (NotImplementedError)


218
219
220
# File 'lib/taka/dom/node.rb', line 218

def namespaceURI
  raise(NotImplementedError.new)
end

#nextSiblingObject



100
101
102
103
# File 'lib/taka/dom/node.rb', line 100

def nextSibling
  return nil if self == parent.children.last
  next_sibling
end

#nodeNameObject



26
27
28
29
30
31
# File 'lib/taka/dom/node.rb', line 26

def nodeName
  return '#text' if text?
  return '#comment' if comment?
  return '#document' if self == document
  node_name
end

#nodeTypeObject



74
75
76
# File 'lib/taka/dom/node.rb', line 74

def nodeType
  node_type
end

#nodeValueObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/taka/dom/node.rb', line 33

def nodeValue
  return nil if [
    ELEMENT_NODE,
    ENTITY_NODE,
    ENTITY_REF_NODE,
    DOCUMENT_NODE,
    DOCUMENT_TYPE_NODE,
    DOCUMENT_FRAG_NODE,
    NOTATION_NODE,
    DTD_NODE,
    ENTITY_DECL,
    NAMESPACE_DECL,
  ].include?(nodeType)
  content
end

#nodeValue=(value) ⇒ Object

Raises:

  • (NotImplementedError)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/taka/dom/node.rb', line 49

def nodeValue= value
  if read_only?
    raise DOMException.new(DOMException::NO_MODIFICATION_ALLOWED_ERR)
  end

  return if [
    ELEMENT_NODE,
    ENTITY_REF_NODE,
    DTD_NODE,
    DOCUMENT_FRAG_NODE,
    DOCUMENT_NODE,
  ].include?(nodeType)

  if [
    CDATA_SECTION_NODE,
    COMMENT_NODE,
    TEXT_NODE,
    PI_NODE,
    ATTRIBUTE_NODE,
  ].include?(nodeType)
    return self.content = value
  end
  raise(NotImplementedError.new)
end

#normalizeObject

Raises:

  • (NotImplementedError)


210
211
212
# File 'lib/taka/dom/node.rb', line 210

def normalize
  raise(NotImplementedError.new)
end

#ownerDocumentObject



113
114
115
116
# File 'lib/taka/dom/node.rb', line 113

def ownerDocument
  return nil if self == document
  document
end

#parentNodeObject



78
79
80
# File 'lib/taka/dom/node.rb', line 78

def parentNode
  parent
end

#prefixObject

Raises:

  • (NotImplementedError)


222
223
224
# File 'lib/taka/dom/node.rb', line 222

def prefix
  raise(NotImplementedError.new)
end

#prefix=(_) ⇒ Object

Raises:

  • (NotImplementedError)


226
227
228
# File 'lib/taka/dom/node.rb', line 226

def prefix=(_)
  raise(NotImplementedError.new)
end

#previousSiblingObject



96
97
98
# File 'lib/taka/dom/node.rb', line 96

def previousSibling
  previous_sibling
end

#removeChild(old_child) ⇒ Object



166
167
168
169
170
171
172
173
174
# File 'lib/taka/dom/node.rb', line 166

def removeChild old_child
  if old_child.read_only?
    raise DOMException.new(DOMException::NO_MODIFICATION_ALLOWED_ERR)
  end
  unless children.include?(old_child)
    raise DOMException.new(DOMException::NOT_FOUND_ERR)
  end
  old_child.remove
end

#replaceChild(new_child, old_child) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/taka/dom/node.rb', line 147

def replaceChild new_child, old_child
  unless can_append?(new_child)
    raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
  end
  if old_child.read_only?
    raise DOMException.new(DOMException::NO_MODIFICATION_ALLOWED_ERR)
  end
  if self.document != new_child.document
    raise DOMException.new(DOMException::WRONG_DOCUMENT_ERR)
  end
  if ancestors.include?(new_child)
    raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
  end
  unless children.include?(old_child)
    raise DOMException.new(DOMException::NOT_FOUND_ERR)
  end
  old_child.replace new_child
end

#setUserData(key, data, handler) ⇒ Object

Raises:

  • (NotImplementedError)


279
280
281
# File 'lib/taka/dom/node.rb', line 279

def setUserData(key, data, handler)
  raise(NotImplementedError.new)
end

#textContentObject



252
253
254
# File 'lib/taka/dom/node.rb', line 252

def textContent
  content
end

#textContent=(string) ⇒ Object



256
257
258
# File 'lib/taka/dom/node.rb', line 256

def textContent= string
  self.content = string
end