Class

class that Parses String’s into URI’s

It contains a Hash set of patterns and Regexp’s that match and validate.

Attributes
Read

The Hash of patterns.

see also URI::Parser.initialize_pattern

Class Methods

Synopsis

URI::Parser.new([opts])

Args

The constructor accepts a hash as options for parser. Keys of options are pattern names of URI components and values of options are pattern strings. The constructor generates set of regexps for parsing URIs.

You can use the following keys:

* :ESCAPED (URI::PATTERN::ESCAPED in default)
* :UNRESERVED (URI::PATTERN::UNRESERVED in default)
* :DOMLABEL (URI::PATTERN::DOMLABEL in default)
* :TOPLABEL (URI::PATTERN::TOPLABEL in default)
* :HOSTNAME (URI::PATTERN::HOSTNAME in default)

Examples

p = URI::Parser.new(:ESCAPED => "(?:%[a-fA-F0-9]{2}|%u[a-fA-F0-9]{4})")
u = p.parse("http://example.jp/%uABCD") #=> #<URI::HTTP:0xb78cf4f8 URL:http://example.jp/%uABCD>
URI.parse(u.to_s) #=> raises URI::InvalidURIError

s = "http://example.com/ABCD"
u1 = p.parse(s) #=> #<URI::HTTP:0xb78c3220 URL:http://example.com/ABCD>
u2 = URI.parse(s) #=> #<URI::HTTP:0xb78b6d54 URL:http://example.com/ABCD>
u1 == u2 #=> true
u1.eql?(u2) #=> false
Instance Methods
No documentation available

Args

str

String to make safe

unsafe

Regexp to apply. Defaults to self.regexp

Description

constructs a safe String from str, removing unsafe characters, replacing them with codes.

Args

str

String to search

schemes

Patterns to apply to str

Description

Attempts to parse and merge a set of URIs If no block given , then returns the result, else it calls block for each element in result.

see also URI::Parser.make_regexp

Constructs the default Hash of patterns

Constructs the default Hash of Regexp’s

No documentation available

Args

uris

an Array of Strings

Description

Attempts to parse and merge a set of URIs

returns Regexp that is default self.regexp, unless schemes is provided. Then it is a Regexp.union with self.pattern

Args

uri

String

Description

parses uri and constructs either matching URI scheme object (FTP, HTTP, HTTPS, LDAP, LDAPS, or MailTo) or URI::Generic

Usage

p = URI::Parser.new
p.parse("ldap://ldap.example.com/dc=example?user=john")
#=> #<URI::LDAP:0x00000000b9e7e8 URL:ldap://ldap.example.com/dc=example?user=john>

Returns a split URI against regexp

Args

str

String to remove escapes from

unsafe

Regexp to apply. Defaults to self.regexp

Description

Removes escapes from str