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
51 52 53 54 55 56 57 |
# File 'lib/rio/rl/pathmethods.rb', line 51 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
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rio/rl/pathmethods.rb', line 96 def calc_abs_uri_(path_str,base_str) #p 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
109 110 111 |
# File 'lib/rio/rl/pathmethods.rb', line 109 def dirname() ::File.dirname(self.path_no_slash) end |
#join(*args) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/rio/rl/pathmethods.rb', line 75 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
93 94 95 |
# File 'lib/rio/rl/pathmethods.rb', line 93 def merge(other) self.class.new(uri.merge(other.uri)) end |
#parse_url(str) ⇒ Object
83 84 85 |
# File 'lib/rio/rl/pathmethods.rb', line 83 def parse_url(str) ::URI.parse(::URI.escape(str,ESCAPE)) end |
#pathdepth ⇒ Object
47 48 49 50 |
# File 'lib/rio/rl/pathmethods.rb', line 47 def pathdepth() pth = self.path_no_slash (pth == '/' ? 0 : pth.count('/')) end |
#route_from(other) ⇒ Object
87 88 89 |
# File 'lib/rio/rl/pathmethods.rb', line 87 def route_from(other) self.class.new(uri.route_from(other.uri),{:base => other.url}) end |
#route_to(other) ⇒ Object
90 91 92 |
# File 'lib/rio/rl/pathmethods.rb', line 90 def route_to(other) self.class.new(uri.route_to(other.uri),{:base => self.url}) end |
#split ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rio/rl/pathmethods.rb', line 58 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
41 42 43 44 45 46 |
# File 'lib/rio/rl/pathmethods.rb', line 41 def urlroot() return nil unless absolute? cp = self.clone cp.urlpath = self.pathroot cp.url end |