Class: HTTPClient::Site
- Inherits:
-
Object
- Object
- HTTPClient::Site
- Defined in:
- lib/httpclient/session.rb
Overview
Represents a Site: protocol scheme, host String and port Number.
Constant Summary collapse
- EMPTY =
Site.new.freeze
Instance Attribute Summary collapse
-
#host ⇒ Object
(also: #hostname)
Host String.
-
#port ⇒ Object
Port number.
-
#scheme ⇒ Object
Protocol scheme.
Instance Method Summary collapse
-
#==(rhs) ⇒ Object
Returns true is scheme, host and port are ‘==’.
-
#addr ⇒ Object
Returns address String.
-
#eql?(rhs) ⇒ Boolean
Same as ==.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(uri = nil) ⇒ Site
constructor
Creates a new Site based on the given URI.
-
#inspect ⇒ Object
:nodoc:.
-
#match(uri) ⇒ Object
Returns true if scheme, host and port of the given URI matches with this.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(uri = nil) ⇒ Site
Creates a new Site based on the given URI.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/httpclient/session.rb', line 45 def initialize(uri = nil) if uri @scheme = uri.scheme || 'tcp' @host = uri.hostname || '0.0.0.0' @port = uri.port.to_i else @scheme = 'tcp' @host = '0.0.0.0' @port = 0 end end |
Instance Attribute Details
#host ⇒ Object Also known as: hostname
Host String.
39 40 41 |
# File 'lib/httpclient/session.rb', line 39 def host @host end |
#port ⇒ Object
Port number.
42 43 44 |
# File 'lib/httpclient/session.rb', line 42 def port @port end |
#scheme ⇒ Object
Protocol scheme.
37 38 39 |
# File 'lib/httpclient/session.rb', line 37 def scheme @scheme end |
Instance Method Details
#==(rhs) ⇒ Object
Returns true is scheme, host and port are ‘==’
63 64 65 |
# File 'lib/httpclient/session.rb', line 63 def ==(rhs) (@scheme == rhs.scheme) and (@host == rhs.host) and (@port == rhs.port) end |
#addr ⇒ Object
Returns address String.
58 59 60 |
# File 'lib/httpclient/session.rb', line 58 def addr "#{@scheme}://#{@host}:#{@port.to_s}" end |
#eql?(rhs) ⇒ Boolean
Same as ==.
68 69 70 |
# File 'lib/httpclient/session.rb', line 68 def eql?(rhs) self == rhs end |
#hash ⇒ Object
:nodoc:
72 73 74 |
# File 'lib/httpclient/session.rb', line 72 def hash # :nodoc: [@scheme, @host, @port].hash end |
#inspect ⇒ Object
:nodoc:
85 86 87 |
# File 'lib/httpclient/session.rb', line 85 def inspect # :nodoc: sprintf("#<%s:0x%x %s>", self.class.name, __id__, addr) end |
#match(uri) ⇒ Object
Returns true if scheme, host and port of the given URI matches with this.
81 82 83 |
# File 'lib/httpclient/session.rb', line 81 def match(uri) (@scheme == uri.scheme) and (@host == uri.host) and (@port == uri.port.to_i) end |
#to_s ⇒ Object
:nodoc:
76 77 78 |
# File 'lib/httpclient/session.rb', line 76 def to_s # :nodoc: addr end |