The UriFormatter handles URIs from user-input and escaping.
uf = Gem::UriFormatter.new 'example.com'
p uf.normalize
Instance Attribute Summary collapse
The URI to be formatted.
Escapes the #uri for use as a CGI parameter.
Creates a new URI formatter for uri
.
Normalize the URI by adding “http://” if it is missing.
Unescapes the #uri which came from a CGI parameter.
Creates a new URI formatter for uri
.
19 20 21 22 23 24
# File 'lib/rubygems/uri_formatter.rb', line 19 def initialize(uri) require "cgi/escape" require "cgi/util" unless defined?(CGI::EscapeExt) @uri = uri endInstance Attribute Details #uri ⇒ Object
14 15 16
# File 'lib/rubygems/uri_formatter.rb', line 14 def uri @uri endInstance Method Details #escape ⇒ Object
Escapes the #uri for use as a CGI parameter
29 30 31 32
# File 'lib/rubygems/uri_formatter.rb', line 29 def escape return unless @uri CGI.escape @uri end#normalize ⇒ Object
Normalize the URI by adding “http://” if it is missing.
37 38 39
# File 'lib/rubygems/uri_formatter.rb', line 37 def normalize /^(https?|ftp|file):/i.match?(@uri) ? @uri : "http://#{@uri}" end#unescape ⇒ Object
Unescapes the #uri which came from a CGI parameter
44 45 46 47
# File 'lib/rubygems/uri_formatter.rb', line 44 def unescape return unless @uri CGI.unescape @uri end
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4