Class: Gem::UriFormatter
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubygems/uri_formatter.rb |
Overview
Class Method Summary
-
.new(uri) ⇒ UriFormatter
constructor
Creates a new URI formatter for #uri.
Instance Attribute Summary
-
#uri
readonly
The URI to be formatted.
Instance Method Summary
-
#escape
Escapes the #uri for use as a CGI parameter.
-
#normalize
Normalize the URI by adding “http://” if it is missing.
-
#unescape
Unescapes the #uri which came from a CGI parameter.
Constructor Details
.new(uri) ⇒ UriFormatter
Creates a new URI formatter for #uri.
Instance Attribute Details
#uri (readonly)
The URI to be formatted.
# File 'lib/rubygems/uri_formatter.rb', line 17
attr_reader :uri
Instance Method Details
#escape
Escapes the #uri for use as a CGI parameter
# File 'lib/rubygems/uri_formatter.rb', line 29
def escape return unless @uri CGI.escape @uri end
#normalize
Normalize the URI by adding “http://” if it is missing.
# File 'lib/rubygems/uri_formatter.rb', line 37
def normalize (@uri =~ /^(https?|ftp|file):/i) ? @uri : "http://#{@uri}" end
#unescape
Unescapes the #uri which came from a CGI parameter
# File 'lib/rubygems/uri_formatter.rb', line 44
def unescape return unless @uri CGI.unescape @uri end