Class: HTTP::URI
Constant Summary collapse
- HTTP_SCHEME =
"http"- HTTPS_SCHEME =
"https"
Class Method Summary collapse
-
.form_encode(form_values, sort = false) ⇒ String
Encodes key/value pairs as application/x-www-form-urlencoded.
-
.parse(uri) ⇒ HTTP::URI
Parse the given URI string, returning an HTTP::URI object.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Are these URI objects equal? Normalizes both URIs prior to comparison.
-
#dup ⇒ Object
Duplicated URI.
-
#eql?(other) ⇒ TrueClass, FalseClass
Are these URI objects equal? Does NOT normalizes both URIs prior to comparison.
-
#hash ⇒ Integer
Hash value based off the normalized form of a URI.
- #http? ⇒ True, False
- #https? ⇒ True, False
-
#initialize(options_or_uri = {}) ⇒ HTTP::URI
constructor
Creates an HTTP::URI instance from the given options.
-
#inspect ⇒ String
Human-readable representation of URI.
-
#port ⇒ Integer
Port number, either as specified or the default if unspecified.
-
#to_s ⇒ String
(also: #to_str)
Convert an HTTP::URI to a String.
Constructor Details
#initialize(options_or_uri = {}) ⇒ HTTP::URI
Creates an HTTP::URI instance from the given options
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/http/uri.rb', line 63 def initialize( = {}) case when Hash @uri = Addressable::URI.new() when Addressable::URI @uri = else raise TypeError, "expected Hash for options, got #{options_or_uri.class}" end end |
Class Method Details
.form_encode(form_values, sort = false) ⇒ String
Encodes key/value pairs as application/x-www-form-urlencoded
45 46 47 |
# File 'lib/http/uri.rb', line 45 def self.form_encode(form_values, sort = false) Addressable::URI.form_encode(form_values, sort) end |
.parse(uri) ⇒ HTTP::URI
Parse the given URI string, returning an HTTP::URI object
33 34 35 36 37 |
# File 'lib/http/uri.rb', line 33 def self.parse(uri) return uri if uri.is_a?(self) new(Addressable::URI.parse(uri)) end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Are these URI objects equal? Normalizes both URIs prior to comparison
79 80 81 |
# File 'lib/http/uri.rb', line 79 def ==(other) other.is_a?(URI) && normalize.to_s == other.normalize.to_s end |
#dup ⇒ Object
Returns duplicated URI.
119 120 121 |
# File 'lib/http/uri.rb', line 119 def dup self.class.new @uri.dup end |
#eql?(other) ⇒ TrueClass, FalseClass
Are these URI objects equal? Does NOT normalizes both URIs prior to comparison
88 89 90 |
# File 'lib/http/uri.rb', line 88 def eql?(other) other.is_a?(URI) && to_s == other.to_s end |
#hash ⇒ Integer
Hash value based off the normalized form of a URI
95 96 97 |
# File 'lib/http/uri.rb', line 95 def hash @hash ||= to_s.hash * -1 end |
#http? ⇒ True, False
108 109 110 |
# File 'lib/http/uri.rb', line 108 def http? HTTP_SCHEME == scheme end |
#https? ⇒ True, False
114 115 116 |
# File 'lib/http/uri.rb', line 114 def https? HTTPS_SCHEME == scheme end |
#inspect ⇒ String
Returns human-readable representation of URI.
132 133 134 |
# File 'lib/http/uri.rb', line 132 def inspect format("#<%s:0x%014x URI:%s>", self.class.name, object_id << 1, to_s) end |
#port ⇒ Integer
Port number, either as specified or the default if unspecified
102 103 104 |
# File 'lib/http/uri.rb', line 102 def port @uri.port || @uri.default_port end |
#to_s ⇒ String Also known as: to_str
Convert an HTTP::URI to a String
126 127 128 |
# File 'lib/http/uri.rb', line 126 def to_s @uri.to_s end |