Class: URI::Generic
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_path(path:, fragment: nil, scheme: "file") ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/core_ext/uri.rb', line 10 def from_path(path:, fragment: nil, scheme: "file") # On Windows, if the path begins with the disk name, we need to add a leading slash to make it a valid URI escaped_path = if /^[A-Z]:/i.match?(path) DEFAULT_PARSER.escape("/#{path}") else DEFAULT_PARSER.escape(path) end build(scheme: scheme, path: escaped_path, fragment: fragment) end |
Instance Method Details
#to_standardized_path ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/core_ext/uri.rb', line 25 def to_standardized_path parsed_path = path return unless parsed_path unescaped_path = DEFAULT_PARSER.unescape(parsed_path) # On Windows, when we're getting the file system path back from the URI, we need to remove the leading forward # slash if %r{^/[A-Z]:}i.match?(unescaped_path) unescaped_path.delete_prefix("/") else unescaped_path end end |