Class: HTTPClient::Site

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(uri = nil) ⇒ Site

Creates a new Site based on the given URI.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/httpclient/session.rb', line 44

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

#hostObject Also known as: hostname

Host String.



38
39
40
# File 'lib/httpclient/session.rb', line 38

def host
  @host
end

#portObject

Port number.



41
42
43
# File 'lib/httpclient/session.rb', line 41

def port
  @port
end

#schemeObject

Protocol scheme.



36
37
38
# File 'lib/httpclient/session.rb', line 36

def scheme
  @scheme
end

Instance Method Details

#==(rhs) ⇒ Object

Returns true is scheme, host and port are ‘==’



62
63
64
# File 'lib/httpclient/session.rb', line 62

def ==(rhs)
  (@scheme == rhs.scheme) and (@host == rhs.host) and (@port == rhs.port)
end

#addrObject

Returns address String.



57
58
59
# File 'lib/httpclient/session.rb', line 57

def addr
  "#{@scheme}://#{@host}:#{@port.to_s}"
end

#eql?(rhs) ⇒ Boolean

Same as ==.

Returns:

  • (Boolean)


67
68
69
# File 'lib/httpclient/session.rb', line 67

def eql?(rhs)
  self == rhs
end

#hashObject

:nodoc:



71
72
73
# File 'lib/httpclient/session.rb', line 71

def hash # :nodoc:
  [@scheme, @host, @port].hash
end

#inspectObject

:nodoc:



84
85
86
# File 'lib/httpclient/session.rb', line 84

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.



80
81
82
# File 'lib/httpclient/session.rb', line 80

def match(uri)
  (@scheme == uri.scheme) and (@host == uri.host) and (@port == uri.port.to_i)
end

#to_sObject

:nodoc:



75
76
77
# File 'lib/httpclient/session.rb', line 75

def to_s # :nodoc:
  addr
end