Class: FileSystem::Path

Inherits:
String
  • Object
show all
Defined in:
lib/filesystem.rb

Overview

:nodoc:

Constant Summary collapse

@@getwd =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.getwdObject



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

#absoluteObject



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

#firstObject



335
# File 'lib/filesystem.rb', line 335

def first; self.split( "/" ).first; end

#nodeObject



342
343
344
345
# File 'lib/filesystem.rb', line 342

def node
	self =~ %r{^(.*)/(.*?)$}
	$2
end

#parentObject



337
338
339
340
# File 'lib/filesystem.rb', line 337

def parent
	self =~ %r{^(.*)/(.*?)$}
	$1
end

#sizeObject



347
# File 'lib/filesystem.rb', line 347

def size; self.split( '/' ).size; end

#stripObject



349
# File 'lib/filesystem.rb', line 349

def strip; self.gsub( %r{^/+}, '' ).gsub( %r{/+$}, '' ); end