Module: RIO::RL::PathMethods
- Included in:
- ZipFile::RootDir::RL
- Defined in:
- lib/rio/rl/pathmethods.rb
Instance Method Summary collapse
- #_parts ⇒ Object
- #calc_abs_uri_(path_str, base_str) ⇒ Object
- #dirname ⇒ Object
- #join(*args) ⇒ Object
- #merge(other) ⇒ Object
- #parse_url(str) ⇒ Object
- #pathdepth ⇒ Object
- #route_from(other) ⇒ Object
- #route_to(other) ⇒ Object
- #split ⇒ Object
- #urlroot ⇒ Object
Instance Method Details
#_parts ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/rio/rl/pathmethods.rb', line 40 def _parts() pr = self.pathroot ur = self.urlroot.sub(/#{pr}$/,'') up = self.urlpath.sub(/^#{pr}/,'') [ur,pr,up] end |
#calc_abs_uri_(path_str, base_str) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rio/rl/pathmethods.rb', line 85 def calc_abs_uri_(path_str,base_str) path = URI(path_str) return path unless base_str if path_str[0,1] != '/' and base_str[0,1] == '/' abs_str = [base_str,path_str].join('/').squeeze('/') return URI(abs_str) end base = URI(base_str) abs = base.merge(path) return abs end |
#dirname ⇒ Object
97 98 99 |
# File 'lib/rio/rl/pathmethods.rb', line 97 def dirname() ::File.dirname(self.path_no_slash) end |
#join(*args) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/rio/rl/pathmethods.rb', line 64 def join(*args) return self if args.empty? sa = args.map { |arg| ::URI.escape(arg.to_s,ESCAPE) } sa.unshift(self.urlpath) unless self.urlpath.empty? self.urlpath = sa.join('/').squeeze('/') self end |
#merge(other) ⇒ Object
82 83 84 |
# File 'lib/rio/rl/pathmethods.rb', line 82 def merge(other) self.class.new(uri.merge(other.uri)) end |
#parse_url(str) ⇒ Object
72 73 74 |
# File 'lib/rio/rl/pathmethods.rb', line 72 def parse_url(str) ::URI.parse(::URI.escape(str,ESCAPE)) end |
#pathdepth ⇒ Object
36 37 38 39 |
# File 'lib/rio/rl/pathmethods.rb', line 36 def pathdepth() pth = self.path_no_slash (pth == '/' ? 0 : pth.count('/')) end |
#route_from(other) ⇒ Object
76 77 78 |
# File 'lib/rio/rl/pathmethods.rb', line 76 def route_from(other) self.class.new(uri.route_from(other.uri),{:base => other.url}) end |
#route_to(other) ⇒ Object
79 80 81 |
# File 'lib/rio/rl/pathmethods.rb', line 79 def route_to(other) self.class.new(uri.route_to(other.uri),{:base => self.url}) end |
#split ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rio/rl/pathmethods.rb', line 47 def split() if absolute? parts = self._parts sparts = [] sparts << parts[0] + parts[1] sparts += parts[2].split('/') else sparts = self.urlpath.split('/') end require 'rio/to_rio' rlparts = sparts.map { |str| self.class.new(str) } (1...sparts.length).each { |i| rlparts[i].base = rlparts[i-1].abs.url + '/' } rlparts end |
#urlroot ⇒ Object
30 31 32 33 34 35 |
# File 'lib/rio/rl/pathmethods.rb', line 30 def urlroot() return nil unless absolute? cp = self.clone cp.urlpath = self.pathroot cp.url end |