class HTree::Context
Attributes
namespaces[R]
Public Class Methods
new(namespaces=nil)
click to toggle source
The optional argument `namespaces' should be a hash or nil. HTree::DefaultNamespaces is used if nil is specified.
If it is a hash, its key should be nil or a string. nil means default namespace. The string means some prefix which must not be empty.
The hash value should be a string. The empty string “” means unbound namespace.
# File htree/context.rb, line 18 def initialize(namespaces=nil) namespaces ||= DefaultNamespaces namespaces.each_pair {|k, v| check_namespace_prefix(k) check_namespace_uri(v) } namespaces = namespaces.dup.freeze unless namespaces.frozen? @namespaces = namespaces end
Public Instance Methods
namespace_uri(prefix)
click to toggle source
return a namespace URI corresponding to prefix. It returns nil if prefix is not defined.
# File htree/context.rb, line 31 def namespace_uri(prefix) @namespaces[prefix] end
subst_namespaces(declared_namespaces)
click to toggle source
generate a new Context object which namespaces are substituted by a hash declared_namespaces.
# File htree/context.rb, line 37 def subst_namespaces(declared_namespaces) namespaces = @namespaces.dup declared_namespaces.each {|k, v| check_namespace_prefix(k) check_namespace_uri(v) namespaces[k] = v } if namespaces == @namespaces self else Context.new(namespaces) end end