class AmazingPrint::Formatters::GetChildItem
Constants
- FILE_ATTRIBUTE_ARCHIVE
docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
- FILE_ATTRIBUTE_HIDDEN
- FILE_ATTRIBUTE_READONLY
- FILE_ATTRIBUTE_SYSTEM
Public Class Methods
new(fname)
click to toggle source
# File lib/amazing_print/formatters/mswin_helper.rb, line 15 def initialize(fname) @fname = fname @stat = File.send(File.symlink?(@fname) ? :lstat : :stat, @fname) @attrs = Kernel32::GetFileAttributesA @fname end
Public Instance Methods
last_write_time()
click to toggle source
# File lib/amazing_print/formatters/mswin_helper.rb, line 38 def last_write_time @stat.mtime.strftime '%Y-%m-%d %H:%M' end
length()
click to toggle source
# File lib/amazing_print/formatters/mswin_helper.rb, line 42 def length @stat.file? ? @stat.size.to_s : '' end
mode()
click to toggle source
# File lib/amazing_print/formatters/mswin_helper.rb, line 27 def mode r = ['-'] * 6 r[0] = 'd' if @stat.directory? r[1] = 'a' unless (@attrs & FILE_ATTRIBUTE_ARCHIVE).zero? r[2] = 'r' unless (@attrs & FILE_ATTRIBUTE_READONLY).zero? r[3] = 'h' unless (@attrs & FILE_ATTRIBUTE_HIDDEN).zero? r[4] = 's' unless (@attrs & FILE_ATTRIBUTE_SYSTEM).zero? r[5] = 'l' if File.symlink? @fname r.join end
name()
click to toggle source
# File lib/amazing_print/formatters/mswin_helper.rb, line 46 def name @fname end
to_s()
click to toggle source
# File lib/amazing_print/formatters/mswin_helper.rb, line 50 def to_s format '%-12<Mode>s %<LastWriteTime>s %14<Length>s %<Name>s', { Mode: mode, LastWriteTime: last_write_time, Length: length, Name: name } end