Class: Kamerling::Addr

Inherits:
Value
  • Object
show all
Defined in:
lib/kamerling/addr.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value

vals

Class Method Details

.[](host, port, prot) ⇒ Object



9
10
11
# File 'lib/kamerling/addr.rb', line 9

def self.[](host, port, prot)
  new(host: host, port: port, prot: prot)
end

Instance Method Details

#connectable?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/kamerling/addr.rb', line 13

def connectable?
  TCPSocket.open(*self).close
  true
rescue Errno::ECONNREFUSED
  false
end

#to_aObject



20
21
22
# File 'lib/kamerling/addr.rb', line 20

def to_a
  [host, port]
end

#to_hObject



24
25
26
# File 'lib/kamerling/addr.rb', line 24

def to_h
  attributes.merge(prot: prot.to_s)
end

#to_sObject



28
29
30
# File 'lib/kamerling/addr.rb', line 28

def to_s
  uri.to_s
end

#uriObject



32
33
34
# File 'lib/kamerling/addr.rb', line 32

def uri
  URI.parse("#{prot.downcase}://#{host}:#{port}")
end