Class: XML::DOM::NodeList
- Inherits:
-
Object
- Object
- XML::DOM::NodeList
- Includes:
- Enumerable
- Defined in:
- lib/xml/dom/core.rb,
lib/xml/dom/digest.rb,
lib/xml/dom2/nodelist.rb
Overview
Class XML::DOM::NodeList
Instance Method Summary collapse
-
#+(nodes) ⇒ Object
— NodeList#+(nodes).
-
#<<(nodes) ⇒ Object
modified by Masaki Fukushima.
-
#[](index) ⇒ Object
— NodeList#[](index).
-
#[]=(*p) ⇒ Object
— NodeList#[]=(*p).
-
#_getValues(names) ⇒ Object
get nodeValues by names names ::= name (‘|’ name)*.
-
#each ⇒ Object
— NodeList#each.
-
#initialize(nodes = nil) ⇒ NodeList
constructor
Class Methods.
-
#item(index) ⇒ Object
[DOM].
-
#pop ⇒ Object
— NodeList#pop.
-
#push(*nodes) ⇒ Object
(also: #concat)
— NodeList#push(*nodes).
-
#reverse ⇒ Object
— NodeList#reverse.
-
#reversible_each(reverse = false) ⇒ Object
[Masaki Fukushima].
-
#shift ⇒ Object
— NodeList#shift.
-
#size ⇒ Object
(also: #length)
— NodeList#size().
-
#to_a ⇒ Object
— NodeList#to_a.
-
#to_s ⇒ Object
— NodeList#to_s.
Constructor Details
#initialize(nodes = nil) ⇒ NodeList
1221 1222 1223 1224 1225 1226 1227 1228 1229 |
# File 'lib/xml/dom/core.rb', line 1221 def initialize(nodes = nil) if nodes.nil? @nodes = [] elsif nodes.is_a?(Array) @nodes = nodes else raise "parameter error" end end |
Instance Method Details
#+(nodes) ⇒ Object
— NodeList#+(nodes)
return the newly created concatenated NodeList.
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 |
# File 'lib/xml/dom/core.rb', line 1382 def +(nodes) if nodes.nil? NodeList.new(@nodes) elsif nodes.is_a?(Array) NodeList.new(@nodes + nodes) elsif nodes.is_a?(NodeList) NodeList.new(@nodes + nodes.to_a) elsif nodes.is_a?(Node) NodeList.new(@nodes + [nodes]) else raise "parameter error" end end |
#<<(nodes) ⇒ Object
modified by Masaki Fukushima
1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 |
# File 'lib/xml/dom/core.rb', line 1402 def <<(nodes) if nodes.nil? ## no change elsif nodes.is_a?(Array) @nodes.concat(nodes) elsif nodes.is_a?(NodeList) @nodes.concat(nodes.to_a) elsif nodes.is_a?(Node) @nodes << nodes else raise "parameter error" end self end |
#[](index) ⇒ Object
— NodeList#[](index)
return indexth node of the NodeList.
1259 1260 1261 |
# File 'lib/xml/dom/core.rb', line 1259 def [](index) @nodes[index] end |
#[]=(*p) ⇒ Object
— NodeList#[]=(*p)
set node of indexth node of the NodeList.
1268 1269 1270 1271 1272 1273 1274 |
# File 'lib/xml/dom/core.rb', line 1268 def []=(*p) if p.length == 2 @nodes[p[0]] = p[1] elsif p.length == 3 @nodes[p[0], p[1]] = p[2] end end |
#_getValues(names) ⇒ Object
get nodeValues by names
names ::= name ('|' name)*
1419 1420 1421 1422 1423 1424 1425 1426 1427 |
# File 'lib/xml/dom/core.rb', line 1419 def _getValues(names) ret = [] names.split('|').each do |name| if !@nodes[name].nil? ret.push(@nodes[name].nodeValue) end end ret end |
#each ⇒ Object
— NodeList#each
iterates over each node of the NodeList.
1281 1282 1283 1284 1285 |
# File 'lib/xml/dom/core.rb', line 1281 def each @nodes.each do |value| yield(value) end end |
#item(index) ⇒ Object
- DOM
1240 1241 1242 |
# File 'lib/xml/dom/core.rb', line 1240 def item(index) @nodes[index] end |
#pop ⇒ Object
— NodeList#pop
pops and returns the last node of the NodeList.
1337 1338 1339 |
# File 'lib/xml/dom/core.rb', line 1337 def pop @nodes.pop end |
#push(*nodes) ⇒ Object Also known as: concat
— NodeList#push(*nodes)
adds nodes into the NodeList.
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 |
# File 'lib/xml/dom/core.rb', line 1310 def push(*nodes) nodes.each do |node| if node.is_a?(Array) self.push(*node) elsif node.is_a?(NodeList) @nodes.concat(node.to_a) elsif node.is_a?(Node) @nodes << node else raise "parameter error" end end self end |
#reverse ⇒ Object
— NodeList#reverse
returns the reversed NodeList.
1364 1365 1366 |
# File 'lib/xml/dom/core.rb', line 1364 def reverse @nodes.reverse end |
#reversible_each(reverse = false) ⇒ Object
- Masaki Fukushima
1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 |
# File 'lib/xml/dom/core.rb', line 1293 def reversible_each(reverse = false) if !reverse @nodes.each do |value| yield(value) end else @nodes.reverse_each do |value| yield(value) end end end |
#shift ⇒ Object
— NodeList#shift
removes and returns the first node of the NodeList.
1346 1347 1348 |
# File 'lib/xml/dom/core.rb', line 1346 def shift @nodes.shift end |
#size ⇒ Object Also known as: length
— NodeList#size()
return size of NodeList.
1249 1250 1251 |
# File 'lib/xml/dom/core.rb', line 1249 def size @nodes.length end |
#to_a ⇒ Object
— NodeList#to_a
converts the NodeList into an array.
1373 1374 1375 |
# File 'lib/xml/dom/core.rb', line 1373 def to_a @nodes end |
#to_s ⇒ Object
— NodeList#to_s
returns the string representation of the NodeList.
1355 1356 1357 |
# File 'lib/xml/dom/core.rb', line 1355 def to_s @nodes.to_s end |