Class: URL
- Inherits:
-
Object
- Object
- URL
- Defined in:
- lib/common/url.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #add_param(name, value) ⇒ Object
-
#initialize(protocol, address, path) ⇒ URL
constructor
A new instance of URL.
- #to_s ⇒ Object
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
#pid ⇒ Object (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_s ⇒ Object
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 |