Class: XML::DOM::NamedNodeMap

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(nodes = nil) ⇒ NamedNodeMap

Class Methods

--- NamedNodeMap.new(nodes = nil)

creates a new 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

#eachObject

— 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

#sizeObject Also known as: length

DOM


1189
1190
1191
# File 'lib/xml/dom/core.rb', line 1189

def size
  @nodes.length
end