Class: URL

Inherits:
Object
  • Object
show all
Defined in:
lib/common/url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(protocol, address, path) ⇒ URL

Returns a new instance of URL.



27
28
29
30
31
32
33
34
35
# File 'lib/common/url.rb', line 27

def initialize( protocol, address, path )
  @protocol = protocol
  @address = address
  @path = path
  
  # params are stored to list so that we can keep order they have been added
  @paramNames = []
  @paramValuesByName = {}
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



24
25
26
# File 'lib/common/url.rb', line 24

def pid
  @pid
end

Instance Method Details

#add_param(name, value) ⇒ Object



38
39
40
41
# File 'lib/common/url.rb', line 38

def add_param( name, value )
  @paramNames.push( name )
  @paramValuesByName[name] = value
end

#to_sObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/common/url.rb', line 44

def to_s
  url = ''
  url << @protocol + '://' if @protocol != nil
  url << @address if @address != nil
  url << '/' if not url.empty?
  
  # path always exists
  url << @path
  url << '?'
  
  @paramNames.each do |name|
    value = @paramValuesByName[name]
    value = URI.escape( value )
    url << "#{name}=#{value}"
    url << '&'
  end
  
  # last char away (? or & character)
  url.chop
end