Allows the opening of various resources including URIs.
If the first argument responds to the ‘open’ method, ‘open’ is called on it with the rest of the arguments.
If the first argument is a string that begins with <code>(protocol)://<code>, it is parsed by URI.parse
. If the parsed object responds to the ‘open’ method, ‘open’ is called on it with the rest of the arguments.
Otherwise, Kernel#open
is called.
OpenURI::OpenRead#open
provides URI::HTTP#open
, URI::HTTPS#open
and URI::FTP#open
, Kernel#open
.
We can accept URIs and strings that begin with http://, https:// and ftp://. In these cases, the opened file object is extended by OpenURI::Meta
.
URI::split(uri)
Splits the string on following parts and returns array with result:
Scheme
Userinfo
Host
Port
Registry
Path
Opaque
Query
Fragment
require 'uri' URI.split("http://www.ruby-lang.org/") # => ["http", nil, "www.ruby-lang.org", nil, nil, "/", nil, nil, nil]
URI::parse(uri_str)
Creates one of the URI’s subclasses instance from the string.
URI::InvalidURIError
Raised if URI
given is not a correct one.
require 'uri' uri = URI.parse("http://www.ruby-lang.org/") # => #<URI::HTTP http://www.ruby-lang.org/> uri.scheme # => "http" uri.host # => "www.ruby-lang.org"
It’s recommended to first ::escape the provided uri_str
if there are any invalid URI
characters.
URI::join(str[, str, ...])
str
String(s) to work with, will be converted to RFC3986 URIs before merging.
Joins URIs.
require 'uri' URI.join("http://example.com/","main.rbx") # => #<URI::HTTP http://example.com/main.rbx> URI.join('http://example.com', 'foo') # => #<URI::HTTP http://example.com/foo> URI.join('http://example.com', '/foo', '/bar') # => #<URI::HTTP http://example.com/bar> URI.join('http://example.com', '/foo', 'bar') # => #<URI::HTTP http://example.com/bar> URI.join('http://example.com', '/foo/', 'bar') # => #<URI::HTTP http://example.com/foo/bar>
URI::extract(str[, schemes][,&blk])
Extracts URIs from a string. If block given, iterates through all matched URIs. Returns nil if block given or array with matches.
require "uri" URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.") # => ["http://foo.example.com/bla", "mailto:test@example.com"]
URI::regexp([match_schemes])
match_schemes
Array
of schemes. If given, resulting regexp matches to URIs whose scheme is one of the match_schemes.
Returns a Regexp
object which matches to URI-like strings. The Regexp
object returned by this method includes arbitrary number of capture group (parentheses). Never rely on it’s number.
require 'uri' # extract first URI from html_string html_string.slice(URI.regexp) # remove ftp URIs html_string.sub(URI.regexp(['ftp']), '') # You should not rely on the number of parentheses html_string.scan(URI.regexp) do |*matches| p $& end
Sets userinfo, argument is string like ‘name:pass’.
Returns the userinfo, either as ‘user’ or ‘user:password’.
Returns attributes.
Setter for attributes val
.
Attempt to convert rss to a URI
, but just return it if there’s a ::URI::Error
register uri against this name.
test if this uri is registered against this name
Parse uri
into a [uri, option] pair.
The DRbProtocol
module asks each registered protocol in turn to try to parse the URI
. Each protocol signals that it does not handle that URI
by raising a DRbBadScheme
error. If no protocol recognises the URI
, then a DRbBadURI
error is raised.
Parse uri
into a [uri, option] pair.
The DRbProtocol
module asks each registered protocol in turn to try to parse the URI
. Each protocol signals that it does not handle that URI
by raising a DRbBadScheme
error. If no protocol recognises the URI
, then a DRbBadURI
error is raised.