[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Converting relative URLs to absolute?

Nick Woolley

6/30/2005 1:05:00 AM

Hi,

Whilst porting some perl code which uses the URI module:

# convert a relative url to an absolute url
my $val = "../some/relative/url.html";
my $target_url = "http://www.somehost.net/blah/page.h...
my $uri = URI->new_abs($val, $target_url);

# $uri is 'http://www.somehost.net/some/relative/url...

- I discovered that there seems to be no standard library equivalent in
ruby, i.e. for converting relative URIs to absolute ones... or am I just
not looking in the right places? (I looked on Google, ruby-doc.org, in
'Pickaxe', etc.)

Thanks,

Nick


___________________________________________________________
How much free photo storage do you get? Store your holiday
snaps for FREE with Yahoo! Photos http://uk.photos...


1 Answer

Eric Hodel

6/30/2005 1:25:00 AM

0


On 29 Jun 2005, at 18:05, Nick Woolley wrote:

> Hi,
>
> Whilst porting some perl code which uses the URI module:
>
> # convert a relative url to an absolute url
> my $val = "../some/relative/url.html";
> my $target_url = "http://www.som...blah/page.h...
> my $uri = URI->new_abs($val, $target_url);
>
> # $uri is 'http://www.som...some/relative/url...
>
> - I discovered that there seems to be no standard library
> equivalent in ruby, i.e. for converting relative URIs to absolute
> ones... or am I just not looking in the right places? (I looked on
> Google, ruby-doc.org, in 'Pickaxe', etc.)

URI does this

$ irb
irb(main):001:0> require 'uri'
=> true
irb(main):002:0> original_uri = URI.parse "http://www.som...
blah/page.html"
=> #<URI::HTTP:0x19999c URL:http://www.som...blah/page.html>
irb(main):003:0> puts original_uri + "../some/relative/url.html"
http://www.som...some/relative/url.html
=> nil


--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04