Class: OOFile::FsEntry

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

Overview

Abstract class which is the abstract base class for file system instances

Direct Known Subclasses

DirEntry, FileEntry, UnknownEntry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FsEntry

Returns a new instance of FsEntry.



9
10
11
# File 'lib/oofile/filesystem.rb', line 9

def initialize(path)
  @path = File.expand_path(path)
end

Instance Attribute Details

#pathObject (readonly)

This is the canonical path to the file system entry



7
8
9
# File 'lib/oofile/filesystem.rb', line 7

def path
  @path
end

Class Method Details

.from(f) ⇒ Object

creates a file system entry for a fully qualified pathname



48
49
50
51
52
# File 'lib/oofile/filesystem.rb', line 48

def self.from(f) 
  return FileEntry.new(f) if File.file?(f) 
  return DirEntry.new(f)  if File.directory?(f) 
  UnknownEntry.new(f)
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
# File 'lib/oofile/filesystem.rb', line 13

def ==(other)
  self.path==(other.path)
end

#basenameObject



27
28
29
# File 'lib/oofile/filesystem.rb', line 27

def basename
  File::basename(@path)
end

#ctimeObject



35
36
37
# File 'lib/oofile/filesystem.rb', line 35

def ctime
  File::ctime(@path)
end

#dirnameObject



31
32
33
# File 'lib/oofile/filesystem.rb', line 31

def dirname
  File::dirname(@path)
end

#extnameObject



17
18
19
# File 'lib/oofile/filesystem.rb', line 17

def extname
  File::extname(@path)
end

#extnlessObject

the bare filename without the file extension



22
23
24
25
# File 'lib/oofile/filesystem.rb', line 22

def extnless
  b = basename
  b[0,b.size-extname.size]
end

#from(fs_entry) ⇒ Object

creates a file system entry for a filename in the current file system entry object



55
56
57
# File 'lib/oofile/filesystem.rb', line 55

def from(fs_entry)
   FsEntry.from(File.join(@path, fs_entry))
end

#inspectObject



63
64
65
# File 'lib/oofile/filesystem.rb', line 63

def inspect
  "#{self.class.to_s}(#{@path})"
end

#mtimeObject



39
40
41
# File 'lib/oofile/filesystem.rb', line 39

def mtime
  File::mtime(@path)
end

#sizeObject



43
44
45
# File 'lib/oofile/filesystem.rb', line 43

def size
  File.size(@path)
end

#traverse(entry) ⇒ Object

by default we ignore entries that cannot be handled



60
61
# File 'lib/oofile/filesystem.rb', line 60

def traverse(entry)
end