Class: Ru::File
- Inherits:
-
Object
- Object
- Ru::File
- Defined in:
- lib/ru/file.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #basename ⇒ Object (also: #name)
- #ctime ⇒ Object (also: #created_at)
- #extname ⇒ Object
- #format(format = 'l') ⇒ Object
- #ftype ⇒ Object
- #gid ⇒ Object
- #group ⇒ Object
-
#initialize(path) ⇒ File
constructor
A new instance of File.
- #mode ⇒ Object
- #mtime ⇒ Object (also: #updated_at)
- #omode ⇒ Object
- #owner ⇒ Object
- #size ⇒ Object
- #to_s ⇒ Object
- #uid ⇒ Object
- #world_readable? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ File
Returns a new instance of File.
5 6 7 |
# File 'lib/ru/file.rb', line 5 def initialize(path) @path = path end |
Instance Method Details
#<=>(other) ⇒ Object
86 87 88 |
# File 'lib/ru/file.rb', line 86 def <=>(other) name <=> other.name end |
#basename ⇒ Object Also known as: name
9 10 11 |
# File 'lib/ru/file.rb', line 9 def basename delegate_to_file(:basename) end |
#ctime ⇒ Object Also known as: created_at
13 14 15 |
# File 'lib/ru/file.rb', line 13 def ctime delegate_to_file(:ctime) end |
#extname ⇒ Object
17 18 19 |
# File 'lib/ru/file.rb', line 17 def extname delegate_to_file(:extname) end |
#format(format = 'l') ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ru/file.rb', line 21 def format(format='l') separator = "\t" case format when 'l' datetime = ctime.strftime(%w{%Y-%m-%d %H:%M}.join(separator)) return [omode, owner, group, size, datetime, name].join(separator) else raise 'format not supported' end end |
#ftype ⇒ Object
32 33 34 |
# File 'lib/ru/file.rb', line 32 def ftype delegate_to_file(:ftype) end |
#gid ⇒ Object
36 37 38 |
# File 'lib/ru/file.rb', line 36 def gid delegate_to_stat(:gid) end |
#group ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/ru/file.rb', line 40 def group grgid = Etc.getgrgid(gid) if grgid.nil? # running on Windows '' else grgid.name end end |
#mode ⇒ Object
49 50 51 |
# File 'lib/ru/file.rb', line 49 def mode delegate_to_stat(:mode) end |
#mtime ⇒ Object Also known as: updated_at
53 54 55 |
# File 'lib/ru/file.rb', line 53 def mtime delegate_to_file(:mtime) end |
#omode ⇒ Object
57 58 59 |
# File 'lib/ru/file.rb', line 57 def omode '%o' % world_readable? end |
#owner ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/ru/file.rb', line 61 def owner pwuid = Etc.getpwuid(uid) if pwuid.nil? # running on Windows '' else pwuid.name end end |
#size ⇒ Object
70 71 72 |
# File 'lib/ru/file.rb', line 70 def size delegate_to_file(:size) end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/ru/file.rb', line 74 def to_s name end |
#uid ⇒ Object
78 79 80 |
# File 'lib/ru/file.rb', line 78 def uid delegate_to_stat(:uid) end |
#world_readable? ⇒ Boolean
82 83 84 |
# File 'lib/ru/file.rb', line 82 def world_readable? delegate_to_stat(:world_readable?) end |