class Addressable::URI

def self.convert_path(path)

Returns:
  • (Addressable::URI) -

Parameters:
  • path (String, Addressable::URI, #to_str) --
def self.convert_path(path)
  # If we were given nil, return nil.
  return nil unless path
  # If a URI object is passed, just return itself.
  return path if path.kind_of?(self)
  unless path.respond_to?(:to_str)
    raise TypeError, "Can't convert #{path.class} into String."
  end
  # Otherwise, convert to a String
  path = path.to_str.strip
  path.sub!(/^file:\/?\/?/, EMPTY_STR) if path =~ /^file:\/?\/?/
  path = SLASH + path if path =~ /^([a-zA-Z])[\|:]/
  uri = self.parse(path)
  if uri.scheme == nil
    # Adjust windows-style uris
    uri.path.sub!(/^\/?([a-zA-Z])[\|:][\\\/]/) do
      "/#{$1.downcase}:/"
    end
    uri.path.tr!("\\", SLASH)
    if File.exist?(uri.path) &&
        File.stat(uri.path).directory?
      uri.path.chomp!(SLASH)
      uri.path = uri.path + '/'
    end
    # If the path is absolute, set the scheme and host.
    if uri.path.start_with?(SLASH)
      uri.scheme = "file"
      uri.host = EMPTY_STR
    end
    uri.normalize!
  end
  return uri
end