Class: Latte::Address

Inherits:
Object show all
Defined in:
lib/latte/address.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject



3
4
5
# File 'lib/latte/address.rb', line 3

def self.default
  @default ||= new
end

Instance Method Details

#ip_addressObject



15
16
17
18
# File 'lib/latte/address.rb', line 15

def ip_address
  matches = string.scan /(\d+\.\d+\.\d+\.\d+)/
  return matches[0][0] unless matches[0].nil?
end

#portObject



21
22
23
24
# File 'lib/latte/address.rb', line 21

def port
  matches = string.scan /:(\d+)$/
  return matches[0][0].to_i unless matches[0].nil?
end

#protocolObject



9
10
11
12
# File 'lib/latte/address.rb', line 9

def protocol
  matches = string.scan /^(udp|tcp):\/\//
  return matches[0][0] unless matches[0].nil?
end

#to_sObject



32
33
34
# File 'lib/latte/address.rb', line 32

def to_s
  "#{protocol}://#{ip_address}:#{port}"
end