Class: RIO::RL::WithPath

Inherits:
Base show all
Includes:
Error::NotImplemented, PathUtil
Defined in:
lib/rio/rl/withpath.rb,
lib/rio/rl/withpath.rb

Direct Known Subclasses

URIBase

Instance Attribute Summary

Attributes inherited from Base

#fs

Instance Method Summary collapse

Methods included from Error::NotImplemented

#nodef

Methods inherited from Base

#==, #===, #=~, #callstr, #close, #initialize, #initialize_copy, is_riorl?, #length, parse, #rl, split_riorl, subscheme, #to_rl, #to_s, #url

Constructor Details

This class inherits a constructor from RIO::RL::Base

Instance Method Details

#_build(*args) ⇒ Object



242
# File 'lib/rio/rl/withpath.rb', line 242

def _build(*args) RIO::RL::Builder.build(*args) end

#_partsObject

returns an array of parts of a RL. ‘a/b/c’ => [‘a’,‘b’,‘c’] For absolute paths the first component is the pathroot ‘/topdir/dir/file’ => [‘/’,‘topdir’,‘dir’,‘file’] ‘host/dir/file’ => [‘host/’,‘dir’,‘file’] ‘//host/a/b’ => [‘file://host/’,‘a’,‘b’] each element of the array is an RL whose base is set such that the correct absolute path would be returned returns an array of RLs



163
164
165
166
167
168
169
# File 'lib/rio/rl/withpath.rb', line 163

def _parts()
  pr = self.pathroot
  ur = self.urlroot.sub(/#{pr}$/,'')
  up = self.urlpath.sub(/^#{pr}/,'')

  [ur,pr,up]
end

#_uri(arg) ⇒ Object



134
135
136
# File 'lib/rio/rl/withpath.rb', line 134

def _uri(arg)
  arg.kind_of?(::Alt::URI) ? arg.clone : ::Alt::URI.parse(arg.to_s)
end

#abs(thebase = nil) ⇒ Object

returns the absolute path. combines the urlpath with the argument, or the value returned by base() to create an absolute path. returns a RL



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/rio/rl/withpath.rb', line 141

def abs(thebase=nil) 
  thebase ||= self.base
  base_uri = _uri(thebase)
  path_uri = self.uri.clone
  if path_uri.scheme == 'file' and base_uri.scheme != 'file'
    abs_uri = path_uri.abs(base_uri)
  else
    abs_uri = path_uri.abs(base_uri)
  end
  _build(abs_uri,{:fs => self.fs})
end

#base(thebase = nil) ⇒ Object

returns the base of a path. merging the value returned with this yields the absolute path



94
# File 'lib/rio/rl/withpath.rb', line 94

def base(thebase=nil) nodef(thebase) end

#basename(ext) ⇒ Object

returns the tail portion of the path minus the extension returns a RL



212
213
214
215
216
217
218
# File 'lib/rio/rl/withpath.rb', line 212

def basename(ext)
  #p callstr('basename',ext)
  base_rl = self.abs
  base_rl.fspath = fs.dirname(base_rl.fspath_no_slash)
  path_str = fs.basename(self.path,ext)
  _build(path_str,{:base => base_rl.uri, :fs => self.fs})
end

#build_arg0_(path_str) ⇒ Object



219
220
221
# File 'lib/rio/rl/withpath.rb', line 219

def build_arg0_(path_str)
  path_str
end

#dirnameObject

returns the directory portion of the path like File#dirname returns a RL



206
207
208
# File 'lib/rio/rl/withpath.rb', line 206

def dirname() 
  RIO::RL::Builder.build(uri.dirname)
end

#filenameObject

returns the tail portion of the path returns a RL



225
226
227
# File 'lib/rio/rl/withpath.rb', line 225

def filename() 
  basename('')
end

#fspathObject

returns the path as the file system sees it. Spaces are spaces and not %20 etc. This is the path that would be passed to the fs object. For windows RLs this includes the ‘//host’ part and the ‘C:’ part returns a String



107
108
109
# File 'lib/rio/rl/withpath.rb', line 107

def fspath()
  uri.netpath
end

#fspath=(fpth) ⇒ Object



111
112
113
# File 'lib/rio/rl/withpath.rb', line 111

def fspath=(fpth)
  uri.netpath = fpth
end

#fspath_no_slashObject

The value of fspath() with any trailing slash removed returns a String



126
127
128
# File 'lib/rio/rl/withpath.rb', line 126

def fspath_no_slash() 
  fspath.sub(%r{/*$},'')
end

#hostObject

returns the host portion of the URI if their is one otherwise it returns nil returns a String



72
# File 'lib/rio/rl/withpath.rb', line 72

def host() nodef() end

#host=(arg) ⇒ Object



73
# File 'lib/rio/rl/withpath.rb', line 73

def host=(arg) nodef(arg) end

#is_root?(upth) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/rio/rl/withpath.rb', line 115

def is_root?(upth)
  upth =~ %r%^(/?[a-zA-Z]:)?/% or upth =~ %r%^//(#{HOST})%
end

#join(*args) ⇒ Object

changes this RLs path so that it consists of this RL’s path combined with those of its arguments.



191
192
193
194
195
# File 'lib/rio/rl/withpath.rb', line 191

def join(*args)
  return self if args.empty?
  sa = args.map { |arg| arg.to_s }
  join_(sa)
end

#merge(other) ⇒ Object

calls URI#merge returns a RL



232
# File 'lib/rio/rl/withpath.rb', line 232

def merge(other) _build(self.uri.merge(other.uri)) end

#opaqueObject

returns the portion of the URL starting after the colon following the scheme, and ending before the query portion of the URL returns a String



79
# File 'lib/rio/rl/withpath.rb', line 79

def opaque() nodef() end

#openfs_Object

returns an appriate FS object for the scheme



45
# File 'lib/rio/rl/withpath.rb', line 45

def openfs_() nodef() end

#pathObject

For RLs that are on the file system this is fspath() For RLs that are remote (http,ftp) this is urlpath() For RLs that have no path this is nil returns a String



56
# File 'lib/rio/rl/withpath.rb', line 56

def path() nodef{} end

#path=(arg) ⇒ Object



57
# File 'lib/rio/rl/withpath.rb', line 57

def path=(arg) nodef(arg) end

#path_no_slashObject

The value of urlpath() with any trailing slash removed returns a String



121
122
123
# File 'lib/rio/rl/withpath.rb', line 121

def path_no_slash() 
  path.sub(%r{/*$},'')
end

#pathdepthObject



129
130
131
132
# File 'lib/rio/rl/withpath.rb', line 129

def pathdepth()
  pth = self.path_no_slash
  pth.count('/')
end

#pathrootObject

returns the portion of the path that when prepended to the path would make it usable. For paths on the file system this would be ‘/’ For http and ftp paths it would be host/ For zipfile paths it would be ” For windows paths with a drive it would be ‘C:/’ For windows UNC paths it would be ‘//host/’ returns a String



89
# File 'lib/rio/rl/withpath.rb', line 89

def pathroot() nodef() end

#route_from(other) ⇒ Object

calls URI#route_from returns a RL



236
# File 'lib/rio/rl/withpath.rb', line 236

def route_from(other) _build(self.uri.route_from(other.uri),{:base => other.uri}) end

#route_to(other) ⇒ Object

calls URI#route_to returns a RL



240
# File 'lib/rio/rl/withpath.rb', line 240

def route_to(other) _build(self.uri.route_to(other.uri),{:base => self.uri}) end

#schemeObject

when the URL is legal it is the URI scheme otherwise it is one of Rio’s schemes returns a String



67
# File 'lib/rio/rl/withpath.rb', line 67

def scheme() nodef() end

#splitObject



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/rio/rl/withpath.rb', line 170

def split()
  if absolute?
    parts = self._parts
    sparts = []
    sparts << parts[0] + parts[1]
    sparts += parts[2].split('/')
  else
    sparts = self.urlpath.split('/')
  end
  rlparts = sparts.map { |str| self.class.new(str) }
  (1...sparts.length).each { |i|
    base_str = rlparts[i-1].abs.url
    base_str += '/' unless base_str[-1] == ?/
    rlparts[i].base = base_str
  }
  rlparts

end

#uriObject

returns A URI object representation of the RL if one exists otherwise it returns nil returns a URI



62
# File 'lib/rio/rl/withpath.rb', line 62

def uri() nodef() end

#uri_from_string_(str) ⇒ Object



244
245
246
# File 'lib/rio/rl/withpath.rb', line 244

def uri_from_string_(str)
  ::Alt::URI.parse(str)
end

#urlpathObject

returns the path portion of a URL. All spaces would be %20 returns a String



49
# File 'lib/rio/rl/withpath.rb', line 49

def urlpath() nodef() end

#urlpath=(arg) ⇒ Object



50
# File 'lib/rio/rl/withpath.rb', line 50

def urlpath=(arg) nodef(arg) end