The UriFormatter
handles URIs from user-input and escaping.
uf = Gem::UriFormatter.new 'example.com' p uf.normalize #=> 'http://example.com'
Creates a new URI
formatter for uri
.
# File ruby-3.1.2/lib/rubygems/uri_formatter.rb, line 19 def initialize(uri) require 'cgi' @uri = uri end
Normalize the URI
by adding “http://” if it is missing.
# File ruby-3.1.2/lib/rubygems/uri_formatter.rb, line 36 def normalize (@uri =~ /^(https?|ftp|file):/i) ? @uri : "http://#{@uri}" end