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



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

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.



211
212
213
# File 'lib/ass_launcher/support/connection_string.rb', line 211

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



211
212
213
# File 'lib/ass_launcher/support/connection_string.rb', line 211

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:



223
224
225
226
227
228
229
230
# File 'lib/ass_launcher/support/connection_string.rb', line 223

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’



233
234
235
# File 'lib/ass_launcher/support/connection_string.rb', line 233

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