class Recls::Entry

A file-system entry

Attributes

basename[R]

(String) The entry's file name (combination of stem + extension)

compare_path[R]

(String) A normalised form of path that can be used in comparisons

directory[R]

(String) The entry's directory (excluding the drive if on Windows)

directory_parts[R]

([String]) An array of directory parts, where each part ends in Recls::PATH_NAME_SEPARATOR

directory_path[R]

(String) The full path of the entry's directory (taking into account the drive if on Windows)

dirname[R]

(String) The full path of the entry's directory (taking into account the drive if on Windows)

drive[R]

(String) The (Windows) drive. nil if does not exist

extension[R]

(String) The entry's file extension

file_extension[R]

(String) The entry's file extension

file_full_name[R]

(String) The entry's file name (combination of stem + extension)

file_name_only[R]

(String) The entry's file stem

file_short_name[R]

(String) The (Windows) short-form of basename, or nil if not on Windows

path[R]

(String) The full-path of the instance

search_directory[R]

(String) The search directory if specified; nil otherwise

search_relative_directory[R]

(String) The directory relative to search_directory; nil if no search directory specified

search_relative_directory_parts[R]

([String]) The directory_parts relative to search_directory; nil if no search directory specified

search_relative_directory_path[R]

(String) The directory_path relative to search_directory; nil if no search directory specified

search_relative_path[R]

(String) The path relative to search_directory; nil if no search directory specified

short_path[R]

(String) The (Windows) short-form of path, or nil if not on Windows

stem[R]

(String) The entry's file stem

Public Class Methods

new(path, file_stat, search_dir, flags) click to toggle source

initialises an entry instance from the given path, file_stat, and search_dir

# File lib/recls/entry.rb, line 65
def initialize(path, file_stat, search_dir, flags)

        @file_stat           =        file_stat

        @path                        =    Recls::Ximpl.absolute_path path
        @short_path          =       nil
        @compare_path        =      Entry.get_compare_path_ @path
        @hash                        =    @compare_path.hash

        windows_drive, directory, basename, file_name, file_ext = Recls::Ximpl::Util.split_path @path

        @drive = windows_drive
        @directory_path = "#{windows_drive}#{directory}"
        @directory = directory ? directory : ''
        @directory_parts = Recls::Ximpl.directory_parts_from_directory directory
        @file_full_name = basename ? basename : ''
        @file_short_name = nil
        @file_name_only = file_name ? file_name : ''
        @file_extension = file_ext ? file_ext : ''

        @search_directory = search_dir
        @search_relative_path = Recls::Ximpl.derive_relative_path search_dir, @path
        @search_relative_directory_path = Recls::Ximpl.derive_relative_path search_dir, @directory_path
        @search_relative_directory = @search_relative_directory_path
        @search_relative_directory_parts = Recls::Ximpl.directory_parts_from_directory @search_relative_directory

        if 0 != (Recls::MARK_DIRECTORIES & flags) && directory?
                @path                                       = Recls::Ximpl::Util.append_trailing_slash @path
                @search_relative_path       =     Recls::Ximpl::Util.append_trailing_slash @search_relative_path
        end

        @dev =       @file_stat.dev if @file_stat
        @ino =       @file_stat.ino if @file_stat
        @nlink       =     @file_stat.nlink if @file_stat

        if Recls::Ximpl::OS::OS_IS_WINDOWS && @file_stat

                @dev                                =   @file_stat.by_handle_information.volume_id
                @ino                                =   @file_stat.by_handle_information.file_index
                @nlink                              = @file_stat.by_handle_information.num_links
                @short_path                 =     @file_stat.short_path
                @file_short_name    =  Recls::Ximpl::Util.split_path(@short_path)[2]
        else
        end
end

Private Class Methods

get_compare_path_(path) click to toggle source

@!visibility private

# File lib/recls/entry.rb, line 57
def self.get_compare_path_(path)
        return path.upcase if Recls::Ximpl::OS::OS_IS_WINDOWS
        path
end

Public Instance Methods

<=>(rhs) click to toggle source

compares this instance with rhs

# File lib/recls/entry.rb, line 366
def <=>(rhs)

        compare_path <=> rhs.compare_path
end
==(rhs) click to toggle source

determines whether rhs refers to the same path

# File lib/recls/entry.rb, line 353
def ==(rhs)

        case rhs
        when String
                return compare_path == Entry.get_compare_path_(rhs)
        when self.class
                return compare_path == rhs.compare_path
        else
                return false
        end
end
archive?() click to toggle source
WINDOWS-ONLY

Indicates whether the entry has the archive bit

# File lib/recls/entry.rb, line 195
def archive?

        return false if @file_stat.nil?

        @file_stat.archive?
end
compressed?() click to toggle source
WINDOWS-ONLY

Indicates whether the entry has the compressed bit

# File lib/recls/entry.rb, line 227
def compressed?

        return false if @file_stat.nil?

        @file_stat.compressed?
end
dev() click to toggle source

indicates the device of the given entry

On Windows, this will be 0 if the entry cannot be opened

# File lib/recls/entry.rb, line 295
def dev

        @dev
end
device?() click to toggle source
WINDOWS-ONLY

Indicates whether the entry is a device

# File lib/recls/entry.rb, line 203
def device?

        return false if @file_stat.nil?

        @file_stat.device?
end
dir?()
Alias for: directory?
directory?() click to toggle source

indicates whether the given entry represents a directory

# File lib/recls/entry.rb, line 244
def directory?

        return false if @file_stat.nil?

        @file_stat.directory?
end
Also aliased as: dir?
encrypted?() click to toggle source
WINDOWS-ONLY

Indicates whether the entry has the encrypted bit

# File lib/recls/entry.rb, line 235
def encrypted?

        return false if @file_stat.nil?

        @file_stat.encrypted?
end
eql?(rhs) click to toggle source

determines whether rhs is an instance of Entry and refers to the same path

# File lib/recls/entry.rb, line 342
def eql?(rhs)

        case rhs
        when self.class
                return compare_path == rhs.compare_path
        else
                return false
        end
end
exist?() click to toggle source

indicates whether the given entry existed at the time the entry instance was created

# File lib/recls/entry.rb, line 158
def exist?

        return false if @file_stat.nil?

        not @file_stat.nil?
end
file?() click to toggle source

indicates whether the given entry represents a file

# File lib/recls/entry.rb, line 254
def file?

        return false if @file_stat.nil?

        @file_stat.file?
end
hash() click to toggle source

the hash

# File lib/recls/entry.rb, line 372
def hash

        @hash
end
hidden?() click to toggle source

indicates whether the given entry is hidden

# File lib/recls/entry.rb, line 166
def hidden?

        return false if @file_stat.nil?

        @file_stat.hidden?
end
ino() click to toggle source

indicates the ino of the given entry

On Windows, this will be 0 if the entry cannot be opened

# File lib/recls/entry.rb, line 304
def ino

        @ino
end
last_access_time() click to toggle source

indicates the last access time of the entry

# File lib/recls/entry.rb, line 322
def last_access_time

        return nil if @file_stat.nil?

        @file_stat.atime
end
modification_time() click to toggle source

indicates the modification time of the entry

# File lib/recls/entry.rb, line 330
def modification_time

        return nil if @file_stat.nil?

        @file_stat.mtime
end
normal?() click to toggle source
WINDOWS-ONLY

Indicates whether the entry is normal

# File lib/recls/entry.rb, line 211
def normal?

        return false if @file_stat.nil?

        @file_stat.normal?
end
readonly?() click to toggle source

indicates whether the given entry is readonly

# File lib/recls/entry.rb, line 174
def readonly?

        return false if @file_stat.nil?

        not @file_stat.writable?
end
size() click to toggle source

indicates the size of the given entry

# File lib/recls/entry.rb, line 281
def size

        return 0 if @file_stat.nil?

        @file_stat.size
end
socket?() click to toggle source

indicates whether the given entry represents a socket

# File lib/recls/entry.rb, line 270
def socket?

        return false if @file_stat.nil?

        @file_stat.socket?
end
system?() click to toggle source
WINDOWS-ONLY

Indicates whether the entry has the system bit

# File lib/recls/entry.rb, line 187
def system?

        return false if @file_stat.nil?

        @file_stat.system?
end
temporary?() click to toggle source
WINDOWS-ONLY

Indicates whether the entry has the temporary bit

# File lib/recls/entry.rb, line 219
def temporary?

        return false if @file_stat.nil?

        @file_stat.temporary?
end
to_s() click to toggle source

represents the entry as a string (in the form of the full path)

# File lib/recls/entry.rb, line 382
def to_s

        path
end
to_str() click to toggle source

represents the entry as a string (in the form of the full path)

# File lib/recls/entry.rb, line 389
def to_str

        path
end