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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri = nil) ⇒ Site

Creates a new Site based on the given URI.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/httpclient/session.rb', line 36

def initialize(uri = nil)
  if uri
    @scheme = uri.scheme
    @host = uri.host
    @port = uri.port.to_i
  else
    @scheme = 'tcp'
    @host = '0.0.0.0'
    @port = 0
  end
end

Instance Attribute Details

#hostObject (readonly)

Host String.



31
32
33
# File 'lib/httpclient/session.rb', line 31

def host
  @host
end

#portObject (readonly)

Port number.



33
34
35
# File 'lib/httpclient/session.rb', line 33

def port
  @port
end

#schemeObject

Protocol scheme.



29
30
31
# File 'lib/httpclient/session.rb', line 29

def scheme
  @scheme
end

Instance Method Details

#==(rhs) ⇒ Object

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



54
55
56
# File 'lib/httpclient/session.rb', line 54

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

#addrObject

Returns address String.



49
50
51
# File 'lib/httpclient/session.rb', line 49

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

#eql?(rhs) ⇒ Boolean

Same as ==.

Returns:

  • (Boolean)


59
60
61
# File 'lib/httpclient/session.rb', line 59

def eql?(rhs)
  self == rhs
end

#hashObject

:nodoc:



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

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

#inspectObject

:nodoc:



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

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.



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

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

#to_sObject

:nodoc:



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

def to_s # :nodoc:
  addr
end