Class URI::Generic
In: lib/open-uri.rb
lib/uri/generic.rb
Parent: Object

Base class for all URI classes. Implements generic URI syntax as per RFC 2396.

Methods

Included Modules

URI REGEXP

Constants

DEFAULT_PORT = nil
COMPONENT = [ :scheme, :userinfo, :host, :port, :registry, :path, :opaque, :query, :fragment
USE_REGISTRY = false

Attributes

fragment  [R] 
host  [R] 
opaque  [R] 
path  [R] 
port  [R] 
query  [R] 
registry  [R] 
scheme  [R] 

Public Class methods

Synopsis

See new

Description

Creates a new URI::Generic instance from components of URI::Generic with check. Components are: scheme, userinfo, host, port, registry, path, opaque, query and fragment. You can provide arguments either by an Array or a Hash. See new for hash keys to use or for order of array items.

Synopsis

See new

Description

At first, tries to create a new URI::Generic instance using URI::Generic::build. But, if exception URI::InvalidComponentError is raised, then it URI::Escape.escape all URI components and tries again.

Components of the URI in the order.

Returns default port

Args

scheme:Protocol scheme, i.e. ‘http’,’ftp’,’mailto’ and so on.
userinfo:User name and password, i.e. ‘sdmitry:bla‘
host:Server host name
port:Server port
registry:DOC: FIXME!
path:Path on server
opaque:DOC: FIXME!
query:Query data
fragment:A part of URI after ’#’ sign
arg_check:Check arguments [false by default]

Description

Creates a new URI::Generic instance from ``generic’’ components without check.

DOC: FIXME!

Public Instance methods

+(oth)

Alias for merge

-(oth)

Alias for route_from

Compares to URI‘s

absolute()

Alias for absolute?

Checks if URI is an absolute one

returns a proxy URI. The proxy URI is obtained from environment variables such as http_proxy, ftp_proxy, no_proxy, etc. If there is no proper proxy, nil is returned.

Note that capitalized variables (HTTP_PROXY, FTP_PROXY, NO_PROXY, etc.) are examined too.

But http_proxy and HTTP_PROXY is treated specially under CGI environment. It‘s because HTTP_PROXY may be set by Proxy: header. So HTTP_PROXY is not used. http_proxy is not used too if the variable is case insensitive. CGI_HTTP_PROXY can be used instead.

Checks if URI has a path

Args

oth:URI or String

Description

Merges two URI‘s.

Usage

  require 'uri'

  uri = URI.parse("http://my.example.com")
  p uri.merge("/main.rbx?page=1")
  # =>  #<URI::HTTP:0x2021f3b0 URL:http://my.example.com/main.rbx?page=1>

Args

oth:URI or String

Description

Destructive form of merge

Usage

  require 'uri'

  uri = URI.parse("http://my.example.com")
  uri.merge!("/main.rbx?page=1")
  p uri
  # =>  #<URI::HTTP:0x2021f3b0 URL:http://my.example.com/main.rbx?page=1>

Returns normalized URI

Destructive version of normalize

Checks if URI is relative

Args

oth:URI or String

Description

Calculates relative path from oth to self

Usage

  require 'uri'

  uri = URI.parse('http://my.example.com/main.rbx?page=1')
  p uri.route_from('http://my.example.com')
  #=> #<URI::Generic:0x20218858 URL:/main.rbx?page=1>

Args

oth:URI or String

Description

Calculates relative path to oth from self

Usage

  require 'uri'

  uri = URI.parse('http://my.example.com')
  p uri.route_to('http://my.example.com/main.rbx?page=1')
  #=> #<URI::Generic:0x2020c2f6 URL:/main.rbx?page=1>

Args

components:Multiple Symbol arguments defined in URI::HTTP

Description

Selects specified components from URI

Usage

  require 'uri'

  uri = URI.parse('http://myuser:mypass@my.example.com/test.rbx')
  p uri.select(:userinfo, :host, :path)
  # => ["myuser:mypass", "my.example.com", "/test.rbx"]

Constructs String from URI

Sets userinfo, argument is string like ‘name:pass‘

Protected Instance methods

[Validate]

ruby-doc.org is a service of James Britt and Neurogami, a Ruby application development company in Phoenix, AZ.

Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.

For more information on the Ruby programming language, visit ruby-lang.org.

Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.