def self.convert_path(path)
return nil unless path
return path if path.kind_of?(self)
if !path.respond_to?(:to_str)
raise TypeError, "Can't convert #{path.class} into String."
end
path = path.to_str.strip
path.gsub!(/^file:\/?\/?/, EMPTY_STR) if path =~ /^file:\/?\/?/
path = SLASH + path if path =~ /^([a-zA-Z])[\|:]/
uri = self.parse(path)
if uri.scheme == nil
uri.path.gsub!(/^\/?([a-zA-Z])[\|:][\\\/]/) do
"/#{$1.downcase}:/"
end
uri.path.gsub!(/\\/, SLASH)
if File.exists?(uri.path) &&
File.stat(uri.path).directory?
uri.path.gsub!(/\/$/, EMPTY_STR)
uri.path = uri.path + '/'
end
if uri.path =~ /^\//
uri.scheme = "file"
uri.host = EMPTY_STR
end
uri.normalize!
end
return uri
end