Class: FileSystem::Path
- Inherits:
-
String
- Object
- String
- FileSystem::Path
- Defined in:
- lib/filesystem.rb
Overview
:nodoc:
Constant Summary collapse
- @@getwd =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #absolute ⇒ Object
- #first ⇒ Object
- #node ⇒ Object
- #parent ⇒ Object
- #size ⇒ Object
- #strip ⇒ Object
Class Method Details
.getwd ⇒ Object
317 318 319 320 |
# File 'lib/filesystem.rb', line 317 def self.getwd @@getwd = Dir.getwd if @@getwd.nil? @@getwd end |
Instance Method Details
#[](*args) ⇒ Object
322 |
# File 'lib/filesystem.rb', line 322 def []( *args ); Path.new( self.split( "/" )[*args].join( "/" ) ); end |
#absolute ⇒ Object
324 325 326 327 328 329 330 331 332 333 |
# File 'lib/filesystem.rb', line 324 def absolute if self =~ %r{^\w} Path.new( File.join( self.class.getwd, self ) ) else new_str = self.to_s new_str.gsub!( %r{^\.\.}, self.class.getwd + '/..' ) new_str.gsub!( %r{^\.}, self.class.getwd ) Path.new( new_str ) end end |
#first ⇒ Object
335 |
# File 'lib/filesystem.rb', line 335 def first; self.split( "/" ).first; end |
#node ⇒ Object
342 343 344 345 |
# File 'lib/filesystem.rb', line 342 def node self =~ %r{^(.*)/(.*?)$} $2 end |
#parent ⇒ Object
337 338 339 340 |
# File 'lib/filesystem.rb', line 337 def parent self =~ %r{^(.*)/(.*?)$} $1 end |
#size ⇒ Object
347 |
# File 'lib/filesystem.rb', line 347 def size; self.split( '/' ).size; end |
#strip ⇒ Object
349 |
# File 'lib/filesystem.rb', line 349 def strip; self.gsub( %r{^/+}, '' ).gsub( %r{/+$}, '' ); end |