class XML::Smart::Dom::NamespaceSet
Public Class Methods
new(parent,node)
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 8 def initialize(parent,node) @parent = parent @node = node end
Public Instance Methods
===(cls)
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 13 def ===(cls); self.is_a? cls; end
[](name)
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 20 def [](name) if name.nil? || name.respond_to?(:to_s) name = name.to_s unless name.nil? name = nil if name =~ /^xmlns\d*$/ nd = @node.namespace_definitions.find{|n| n.prefix == name} (name.respond_to?(:to_s) || name.nil?) && nd ? Namespace.new(nd) : nil; end end
[]=(name,value)
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 28 def []=(name,value) name = nil if name == 'xmlns' self.add(name,value) end
add(name,value)
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 33 def add(name,value) if (name.respond_to?(:to_s) || name.nil?) && value.respond_to?(:to_s) nnod = Nokogiri::XML::Node.new(@node.name,@node.document) nnew = Element.new(nnod) nold = Element.new(@node) nold.attributes.each do |attr| nnew.attributes[attr.qname.name] = attr.value end ns = nnod.add_namespace_definition(name.nil? ? nil : name.to_s,value.to_s) @node.namespace_definitions.each do |nst| nnod.add_namespace_definition(nst.prefix,nst.href) end nnew.add(nold.children) nold.replace_by(nnew) @node = nnod @parent.instance_variable_set(:@node,@node) @node.document.custom_namespace_prefixes_update @node.document.ns_update Namespace.new(ns) end end
delete_all!()
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 57 def delete_all! nnod = Nokogiri::XML::Node.new(@node.name,@node.document) nnew = Element.new(nnod) nold = Element.new(@node) nold.attributes.each do |attr| nnew.attributes[attr.qname.name] = attr.value end nnew.add(nold.children) nold.replace_by(nnew) @node = nnod @parent.instance_variable_set(:@node,@node) @node.document.custom_namespace_prefixes_update @node.document.ns_update nil end
delete_at(name)
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 79 def delete_at(name) if (name.respond_to?(:to_s) || name.nil?) return false unless @node.namespace_definitions.one?{|e| e.prefix == name} nnod = Nokogiri::XML::Node.new(@node.name,@node.document) nnew = Element.new(nnod) nold = Element.new(@node) nold.attributes.each do |attr| nnew.attributes[attr.qname.name] = attr.value end @node.namespace_definitions.each do |ns| nnod.add_namespace_definition(ns.prefix,ns.href) unless ns.prefix == name end nnew.add(nold.children) nold.replace_by(nnew) @node = nnod @parent.instance_variable_set(:@node,@node) @node.document.custom_namespace_prefixes_update @node.document.ns_update true else false end end
delete_if(&block)
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 104 def delete_if(&block) return self if block.nil? nnod = Nokogiri::XML::Node.new(@node.name,@node.document) nnew = Element.new(nnod) nold = Element.new(@node) nold.attributes.each do |attr| nnew.attributes[attr.qname.name] = attr.value end @node.namespace_definitions.each do |ns| nnod.add_namespace_definition(ns.prefix,ns.href) unless block.call(Dom::smart_helper(ns)) end nnew.add(nold.children) nold.replace_by(nnew) @node = nnod @parent.instance_variable_set(:@node,@node) @node.document.custom_namespace_prefixes_update @node.document.ns_update self end
each(&block)
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 73 def each(&block) @node.namespace_definitions.each do |ns| block.call Namespace.new(ns) end end
empty?()
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 56 def empty?; @node.namespace_definitions.empty?; end
has_ns?(a)
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 15 def has_ns?(a); @node.namespace_definitions.one?{|e| e.href == a || e.prefix == a}; end
length()
click to toggle source
# File lib/xml/smart_domnamespaceset.rb, line 55 def length; @node.namespace_definitions.length; end