Class: AssLauncher::Support::ConnectionString::Server::ServerDescr

Inherits:
Object
  • Object
show all
Defined in:
lib/ass_launcher/support/connection_string.rb

Overview

Simple class host:port

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = nil) ⇒ ServerDescr

Returns a new instance of ServerDescr.

Parameters:

  • host (String)

    hostname

  • port (String) (defaults to: nil)

    port number



207
208
209
210
# File 'lib/ass_launcher/support/connection_string.rb', line 207

def initialize(host, port = nil)
  @host = host.strip
  @port = port.to_s.strip
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



203
204
205
# File 'lib/ass_launcher/support/connection_string.rb', line 203

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



203
204
205
# File 'lib/ass_launcher/support/connection_string.rb', line 203

def port
  @port
end

Class Method Details

.parse(srv_str) ⇒ Arry<ServerDescr>

Parse sting <srv_string>

Parameters:

  • srv_str (String)

    string like ‘host:port,host:port’

Returns:



215
216
217
218
219
220
221
222
# File 'lib/ass_launcher/support/connection_string.rb', line 215

def self.parse(srv_str)
  r = []
  srv_str.split(',').each do |srv|
    srv.strip!
    r << new(* srv.chomp.split(':')) unless srv.empty?
  end
  r
end

Instance Method Details

#to_sString

Returns formated ‘host:port’.

Returns:

  • (String)

    formated ‘host:port’



225
226
227
# File 'lib/ass_launcher/support/connection_string.rb', line 225

def to_s
  "#{host}" + (port.empty? ? '' : ":#{port}")
end