Module: URI
- Defined in:
- lib/spidr/extensions/uri.rb
Class Method Summary collapse
-
.expand_path(path) ⇒ String
Expands a URI decoded path, into a proper absolute path.
Class Method Details
.expand_path(path) ⇒ String
Expands a URI decoded path, into a proper absolute path.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/spidr/extensions/uri.rb', line 29 def URI.(path) dirs = path.split(/\/+/) # append any tailing '/' chars, lost due to String#split dirs << '' if path[-1,1] == '/' new_dirs = [] dirs.each do |dir| if dir == '..' new_dirs.pop elsif dir != '.' new_dirs.push(dir) end end full_path = new_dirs.join('/') # default empty paths to '/' full_path = '/' if full_path.empty? return full_path end |