Class: AmazingPrint::Formatters::GetChildItem
- Defined in:
- lib/amazing_print/formatters/mswin_helper.rb
Constant Summary collapse
- FILE_ATTRIBUTE_ARCHIVE =
docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
0x20
- FILE_ATTRIBUTE_READONLY =
0x1
- FILE_ATTRIBUTE_HIDDEN =
0x2
- FILE_ATTRIBUTE_SYSTEM =
0x4
Instance Method Summary collapse
-
#initialize(fname) ⇒ GetChildItem
constructor
A new instance of GetChildItem.
- #last_write_time ⇒ Object
- #length ⇒ Object
- #mode ⇒ Object
- #name ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(fname) ⇒ GetChildItem
Returns a new instance of GetChildItem.
15 16 17 18 19 |
# 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 |
Instance Method Details
#last_write_time ⇒ Object
38 39 40 |
# File 'lib/amazing_print/formatters/mswin_helper.rb', line 38 def last_write_time @stat.mtime.strftime '%Y-%m-%d %H:%M' end |
#length ⇒ Object
42 43 44 |
# File 'lib/amazing_print/formatters/mswin_helper.rb', line 42 def length @stat.file? ? @stat.size.to_s : '' end |
#mode ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# 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 ⇒ Object
46 47 48 |
# File 'lib/amazing_print/formatters/mswin_helper.rb', line 46 def name @fname end |
#to_s ⇒ Object
50 51 52 53 54 55 56 57 58 |
# 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 |