Abstract

uri.rb is a package for parse URI text string. It conforms RFC 2396 basically. Now it supports only tow schemes, FTP and HTTP.


Contents


API


class URI

URI is a abstract class. But it has common interface to instantiate an URI object.

To instanciate ALL kinds of URI objects, use URI.create. DO NOT use new() directlly to instanciate HTTPURL or others.

To escape query string, use URI#escape. (Thanx NaHi, Wakou)

Getter methods return a component string that is not dup-ed and not freeze-ed.

URI::create(absolute_uri, relative_uri=nil)

creates an URI object from URI text string

If you want to get an URI objects, use this method. DO NOT instanciate HTTPURL or others directlly.

Now, URI creates only two kinds of objects, FTPURL and HTTPURL

precond: absolute_uri and ((relative_uri.nil? and absolute_uri.is_a? String) or
                           (relative_uri.is_a? String and 
                            (absolute_uri.is_a? String or
                             absolute_uri.is_a? URI)))
postcond: const absolute_uri, const relative_uri
return: aURI
raise: URIError if absolute_uri and/or relative_uri are a bad URI

URI::escape(str)

escapes query string. You had better use cgi.rb

URI::unescape(str)

unescape query string.

[](component_name)

returns URI component specified by component_name

each(&block)

Iterats over each `component name' and `component' pair like Hash#each.

scheme

returns `scheme' component.

return: aString, (aString != nil)

==(obj)

Returns true if self.type == obj.type. Or if obj is a String, an URI object is instanciated then it is compared with self.

dup

duplicates self.


class URI::GenericURI <URI

GenericURI is a abstract class. Its super class is URI. Its subclasses are FTPURL, HTTPURL and etc.

A instance of subclass which are subclassed from GenericURI may have scheme, userinfo, host, port, path, query, and fragment.

create_relative_uri is a instance method to create another URI instance relative to the receiver.

create_relative_uri(relative_uri)

create relative URI to self.

raise: URIError if relative_url is not URL text string.

host

returns `host' component.

return: aString (aString != nil)

host=(str)

setter for `host' component.

path

returns `path' component.

return: aString (aString != nil and aString[0] == ?/)

path=(str)

setters for `path' component.

port

returns `port' component.

return: aString (/\A\d+\z/ =~ aString)

port=(port)

setter for `port' component.

raise: URIError if /^\d+$/ !~ port.to_s

query

returns `query' component.

return: nil or aString (does not start with '?' basically)

query=(str)

setter for `query' component.

fragment

returns `fragment' component.

return: nil or aString (does not start with '#' basically)

fragment=(str)

setter for `fragment' component.

userinfo

returns `userinfo' component.

return: nil or aString

userinfo=(str)

setter for `userinfo' component.

==(obj)

compares to obj. Although `fragment' component is not a part of URI, this method compare `fragment' components of self and obj. `host' components are compared case-insensitive. Most components are escaped when they are compared. See RFC for detail.

to_s

returns URI text string


class URI::FTPURL <GenericURI

FTPURL is a class for FTP URL scheme.

WELL_KNOWN_PORT

A String, `21'

user

returns `user' component.

return: nil or aString

password

returns `password' component.

return: nil or aString

password=(str)

setter for `password' component.

typecode

returns `type' component (Object has type method).

return: nil or aString (/\A[aid]\z/ =~ aString)

typecode=(typecode)

setter for `type' component.

raise: URIError if /^[aid]$/ !~ typecode

class URI::HTTPURL <GenericURI

HTTPURL is a class for HTTP URL scheme.

WELL_KNOWN_PORT

A String, `80'.


2000.07.17
greentea@fa2.so-net.ne.jp