Class: Gem::UriFormatter
- Inherits:
- 
      Object
      
        - Object
- Gem::UriFormatter
 
- Defined in:
- lib/rubygems/uri_formatter.rb
Overview
Instance Attribute Summary collapse
- 
  
    
      #uri  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The URI to be formatted. 
Instance Method Summary collapse
- 
  
    
      #escape  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Escapes the #uri for use as a CGI parameter. 
- 
  
    
      #initialize(uri)  ⇒ UriFormatter 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Creates a new URI formatter for uri.
- 
  
    
      #normalize  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Normalize the URI by adding “http://” if it is missing. 
- 
  
    
      #unescape  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Unescapes the #uri which came from a CGI parameter. 
Constructor Details
#initialize(uri) ⇒ UriFormatter
Creates a new URI formatter for uri.
| 19 20 21 22 23 | # File 'lib/rubygems/uri_formatter.rb', line 19 def initialize(uri) require "cgi" @uri = uri end | 
Instance Attribute Details
#uri ⇒ Object (readonly)
The URI to be formatted.
| 14 15 16 | # File 'lib/rubygems/uri_formatter.rb', line 14 def uri @uri end | 
Instance Method Details
#escape ⇒ Object
Escapes the #uri for use as a CGI parameter
| 28 29 30 31 | # File 'lib/rubygems/uri_formatter.rb', line 28 def escape return unless @uri CGI.escape @uri end | 
#normalize ⇒ Object
Normalize the URI by adding “http://” if it is missing.
| 36 37 38 | # File 'lib/rubygems/uri_formatter.rb', line 36 def normalize /^(https?|ftp|file):/i.match?(@uri) ? @uri : "http://#{@uri}" end | 
#unescape ⇒ Object
Unescapes the #uri which came from a CGI parameter
| 43 44 45 46 | # File 'lib/rubygems/uri_formatter.rb', line 43 def unescape return unless @uri CGI.unescape @uri end |