From 1808c94f35ebe65c53a4e02c39c3d88897241c96 Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Wed, 5 Sep 2007 20:46:23 +0000 Subject: [PATCH] Updated to 0.1.0. git-svn-id: svn+ssh://rubyforge.org/var/svn/addressable/trunk@5 43a1db0b-ab41-44e6-b450-8aa639c49ec7 --- CHANGELOG | 4 +++ README | 21 +++++++++++ spec/addressable/uri_spec.rb | 67 ++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 9446e56b..c01d6339 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +=== Addressable 0.1.1 + * updated documentation + * added URI Template variable extraction + === Addressable 0.1.0 * initial release * implementation based on RFC 3986, 3987 diff --git a/README b/README index f3b34118..d329f132 100644 --- a/README +++ b/README @@ -1,3 +1,24 @@ Addressable is a replacement for the URI implementation that is part of Ruby's standard library. It more closely conforms to the relevant RFCs and adds support for IRIs and URI templates. + +Example usage: + + require 'addressable/uri' + + uri = Addressable::URI.parse("http://example.com/path/to/resource/") + uri.scheme + => "http" + uri.host + => "example.com" + uri.path + => "/path/to/resource/" + + Addressable::URI.expand_template("http://example.com/{query}/", { + "query" => "an+example+query" + }) + => # + + uri = Addressable::URI.parse("http://www.詹姆斯.com/") + uri.normalize + => # diff --git a/spec/addressable/uri_spec.rb b/spec/addressable/uri_spec.rb index 34a0e9c6..0fb2ecc6 100644 --- a/spec/addressable/uri_spec.rb +++ b/spec/addressable/uri_spec.rb @@ -36,6 +36,16 @@ def self.transform(name, value) return value.gsub(/ /, "+") if name == "query" return value end + + def self.restore(name, value) + return value.gsub(/\+/, " ") if name == "query" + return value + end + + def self.match(name) + return ".*?" if name == "first" + return ".*" + end end context "A completely nil URI" do @@ -2276,3 +2286,60 @@ def require(path) @mapping).to_s.should == "http://example.com/%257Bb%257D/" end end + +context "http://example.com/search/an+example+search+query/" do + setup do + @uri = Addressable::URI.parse( + "http://example.com/search/an+example+search+query/") + end + + specify "when extracting using the pattern " + + "'http://example.com/search/{query}/' with the " + + "ExampleProcessor to extract values should have the correct mapping" do + @uri.extract_mapping( + "http://example.com/search/{query}/", ExampleProcessor + ).should == { + "query" => "an example search query" + } + end + + specify "when extracting using a non-matching pattern should return nil" do + @uri.extract_mapping( + "http://bogus.com/{thingy}/" + ).should == nil + end +end + +context "http://example.com/a/b/c/" do + setup do + @uri = Addressable::URI.parse( + "http://example.com/a/b/c/") + end + + specify "when extracting using the pattern " + + "'http://example.com/{first}/{second}/' with the " + + "ExampleProcessor to extract values should have the correct mapping" do + @uri.extract_mapping( + "http://example.com/{first}/{second}/", ExampleProcessor + ).should == { + "first" => "a", + "second" => "b/c" + } + end +end + +context "http://example.com/one/spacer/two/" do + setup do + @uri = Addressable::URI.parse("http://example.com/one/spacer/two/") + end + + specify "when extracting using the pattern " + + "'http://example.com/{first}/spacer/{second}/' to extract values " + + "should have the correct mapping" do + @uri.extract_mapping( + "http://example.com/{first}/spacer/{second}/").should == { + "first" => "one", + "second" => "two" + } + end +end