Class: XML::DOM::NamedNodeMap
- Inherits:
-
Object
- Object
- XML::DOM::NamedNodeMap
- Includes:
- Enumerable
- Defined in:
- lib/xml/dom/core.rb,
lib/xml/dom/digest.rb,
lib/xml/dom2/namednodemap.rb
Overview
Class XML::DOM::NamedNodeMap
Instance Method Summary collapse
-
#[](name) ⇒ Object
— NamedNodeMap#[](name).
-
#[]=(name, node) ⇒ Object
— NamedNodeMap#[]=(name, node).
-
#_getValues(names) ⇒ Object
get nodeValues by names names ::= name (‘|’ name)*.
-
#each ⇒ Object
— NamedNodeMap#each().
-
#getNamedItem(name) ⇒ Object
[DOM].
-
#initialize(nodes = nil) ⇒ NamedNodeMap
constructor
Class Methods.
-
#item(index) ⇒ Object
[DOM].
-
#removeNamedItem(name) ⇒ Object
[DOM].
-
#setNamedItem(node) ⇒ Object
[DOM].
-
#size ⇒ Object
(also: #length)
[DOM].
Constructor Details
#initialize(nodes = nil) ⇒ NamedNodeMap
1095 1096 1097 1098 1099 1100 |
# File 'lib/xml/dom/core.rb', line 1095 def initialize(nodes = nil) @nodes = {} nodes.each do |node| @nodes[node.nodeName] = node end if nodes end |
Instance Method Details
#[](name) ⇒ Object
— NamedNodeMap#[](name)
returns nodes associated to name.
1157 1158 1159 |
# File 'lib/xml/dom/core.rb', line 1157 def [](name) @nodes[name] end |
#[]=(name, node) ⇒ Object
— NamedNodeMap#[]=(name, node)
sets node named name.
1166 1167 1168 1169 |
# File 'lib/xml/dom/core.rb', line 1166 def []=(name, node) raise "parameter error" if node.nodeName != name @nodes[name] = node end |
#_getValues(names) ⇒ Object
get nodeValues by names
names ::= name ('|' name)*
1196 1197 1198 1199 1200 1201 1202 1203 1204 |
# File 'lib/xml/dom/core.rb', line 1196 def _getValues(names) ret = [] names.split('|').each do |name| if !@nodes[name].nil? ret.push(@nodes[name].nodeValue) end end ret end |
#each ⇒ Object
— NamedNodeMap#each()
iterates over each pair of name and node(name, node) of the namedNodeMap.
1176 1177 1178 1179 1180 |
# File 'lib/xml/dom/core.rb', line 1176 def each @nodes.each do |key, value| yield(value) end end |
#getNamedItem(name) ⇒ Object
- DOM
1111 1112 1113 |
# File 'lib/xml/dom/core.rb', line 1111 def getNamedItem(name) @nodes[name] end |
#item(index) ⇒ Object
- DOM
1146 1147 1148 1149 1150 |
# File 'lib/xml/dom/core.rb', line 1146 def item(index) v = @nodes.to_a[index] return v[1] if v nil end |
#removeNamedItem(name) ⇒ Object
- DOM
1133 1134 1135 1136 1137 |
# File 'lib/xml/dom/core.rb', line 1133 def removeNamedItem(name) ret = @nodes[name] @nodes[name] = nil ret end |
#setNamedItem(node) ⇒ Object
- DOM
1122 1123 1124 |
# File 'lib/xml/dom/core.rb', line 1122 def setNamedItem(node) @nodes[node.nodeName] = node end |
#size ⇒ Object Also known as: length
- DOM
1189 1190 1191 |
# File 'lib/xml/dom/core.rb', line 1189 def size @nodes.length end |