Skip to content

Commit

Permalink
Updated to 0.1.0.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/addressable/trunk@5 43a1db0b-ab41-44e6-b450-8aa639c49ec7
  • Loading branch information
sporkmonger committed Sep 5, 2007
1 parent 7e6c417 commit 1808c94
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
21 changes: 21 additions & 0 deletions 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"
})
=> #<Addressable::URI:0x123456 URI:http://example.com/an+example+query/>

uri = Addressable::URI.parse("http://www.詹姆斯.com/")
uri.normalize
=> #<Addressable::URI:0x654321 URI:http://www.xn--8ws00zhy3a.com/>
67 changes: 67 additions & 0 deletions spec/addressable/uri_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 1808c94

Please sign in to comment.