Skip to content

Commit

Permalink
find_namespace -> find_namespace_uri
Browse files Browse the repository at this point in the history
  • Loading branch information
mccraigmccraig committed May 10, 2011
1 parent 669c533 commit 3219f5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/rsxml/sexp.rb
Expand Up @@ -79,7 +79,7 @@ def compact_qname(ns_stack, name)
raise "invalid name: #{name}" if !prefix && uri
if prefix
if prefix!="xmlns"
ns = find_namespace(ns_stack, prefix, uri)
ns = find_namespace_uri(ns_stack, prefix, uri)
raise "namespace prefix not bound to a namespace: '#{prefix}'" if ! ns
end
[prefix, local_part].map{|s| s.to_s unless s.to_s.empty?}.compact.join(':')
Expand All @@ -105,15 +105,15 @@ def explode_qname(ns_stack, qname, attr=false)
if prefix=="xmlns" && attr
[local_part, prefix]
else
uri = find_namespace(ns_stack, prefix)
uri = find_namespace_uri(ns_stack, prefix)
raise "namespace prefix not bound: '#{prefix}'" if ! uri
[local_part, prefix, uri]
end
else
if attr
local_part
else
default_uri = find_namespace(ns_stack, "")
default_uri = find_namespace_uri(ns_stack, "")
if default_uri
[local_part, "", default_uri]
else
Expand All @@ -135,7 +135,7 @@ def split_qname(qname)
end

# returns the namespace uri for a prefix, if declared in the stack
def find_namespace(ns_stack, prefix, uri_check=nil)
def find_namespace_uri(ns_stack, prefix, uri_check=nil)
tns = ns_stack.reverse.find{|ns| ns.has_key?(prefix)}
uri = tns[prefix] if tns
raise "prefix: '#{prefix}' is bound to uri: '#{uri}', but should be '#{uri_check}'" if uri_check && uri && uri!=uri_check
Expand Down Expand Up @@ -177,7 +177,7 @@ def extract_explicit_namespace_bindings(tag, attrs)
# +ns_explicit+ is the explicit refs for a tag
def undeclared_namespaces(ns_stack, ns_explicit)
Hash[ns_explicit.map do |prefix,uri|
[prefix, uri] if !find_namespace(ns_stack, prefix, uri)
[prefix, uri] if !find_namespace_uri(ns_stack, prefix, uri)
end.compact]
end

Expand Down
8 changes: 4 additions & 4 deletions spec/rsxml/sexp_spec.rb
Expand Up @@ -3,19 +3,19 @@
module Rsxml
describe "find_namespace" do
it "should find a namespace uri in a stack of prefix bindings" do
Rsxml::Sexp.find_namespace([{"foo"=>"http://foo.com/foo"},
Rsxml::Sexp.find_namespace_uri([{"foo"=>"http://foo.com/foo"},
{"bar"=>"http://bar.com/bar"}],
"bar").should == "http://bar.com/bar"
Rsxml::Sexp.find_namespace([{"foo"=>"http://foo.com/foo"},
Rsxml::Sexp.find_namespace_uri([{"foo"=>"http://foo.com/foo"},
{"bar"=>"http://bar.com/bar"}],
"foo").should == "http://foo.com/foo"
end

it "should return nil if there is no matching binding" do
Rsxml::Sexp.find_namespace([{"foo"=>"http://foo.com/foo"},
Rsxml::Sexp.find_namespace_uri([{"foo"=>"http://foo.com/foo"},
{"bar"=>"http://bar.com/bar"}],
"blah").should == nil
Rsxml::Sexp.find_namespace([],
Rsxml::Sexp.find_namespace_uri([],
"blah").should == nil
end

Expand Down

0 comments on commit 3219f5d

Please sign in to comment.