Class: MockFS::Path

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

Overview

:nodoc:

Constant Summary collapse

@@getwd =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.getwdObject



524
525
526
527
# File 'lib/mockfs.rb', line 524

def self.getwd
	@@getwd = Dir.getwd if @@getwd.nil?
	@@getwd
end

Instance Method Details

#[](*args) ⇒ Object



529
530
531
532
533
534
535
# File 'lib/mockfs.rb', line 529

def []( *args )
	if args.size == 1 and args.first.is_a? Fixnum
		Path.new self.split( "/" )[*args]
	else
		Path.new self.split( "/" )[*args].join( "/" )
	end
end

#absoluteObject



537
538
539
540
541
542
543
544
545
546
# File 'lib/mockfs.rb', line 537

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



548
# File 'lib/mockfs.rb', line 548

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

#lastObject



550
# File 'lib/mockfs.rb', line 550

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

#nodeObject



552
553
554
555
# File 'lib/mockfs.rb', line 552

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

#parentObject



557
558
559
560
# File 'lib/mockfs.rb', line 557

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

#sizeObject



562
# File 'lib/mockfs.rb', line 562

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

#stripObject



564
# File 'lib/mockfs.rb', line 564

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