Class: Ru::File

Inherits:
Object
  • Object
show all
Defined in:
lib/ru/file.rb

Instance Method Summary collapse

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



76
77
78
# File 'lib/ru/file.rb', line 76

def <=>(other)
  name <=> other.name
end

#basenameObject Also known as: name



9
10
11
# File 'lib/ru/file.rb', line 9

def basename
  delegate_to_file(:basename)
end

#ctimeObject Also known as: created_at



13
14
15
# File 'lib/ru/file.rb', line 13

def ctime
  delegate_to_file(:ctime)
end

#extnameObject



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

#ftypeObject



32
33
34
# File 'lib/ru/file.rb', line 32

def ftype
  delegate_to_file(:ftype)
end

#gidObject



36
37
38
# File 'lib/ru/file.rb', line 36

def gid
  delegate_to_stat(:gid)
end

#groupObject



40
41
42
# File 'lib/ru/file.rb', line 40

def group
  Etc.getgrgid(gid).name
end

#modeObject



44
45
46
# File 'lib/ru/file.rb', line 44

def mode
  delegate_to_stat(:mode)
end

#mtimeObject Also known as: updated_at



48
49
50
# File 'lib/ru/file.rb', line 48

def mtime
  delegate_to_file(:mtime)
end

#omodeObject



52
53
54
# File 'lib/ru/file.rb', line 52

def omode
  '%o' % world_readable?
end

#ownerObject



56
57
58
# File 'lib/ru/file.rb', line 56

def owner
  Etc.getpwuid(uid).name
end

#sizeObject



60
61
62
# File 'lib/ru/file.rb', line 60

def size
  delegate_to_file(:size)
end

#to_sObject



64
65
66
# File 'lib/ru/file.rb', line 64

def to_s
  name
end

#uidObject



68
69
70
# File 'lib/ru/file.rb', line 68

def uid
  delegate_to_stat(:uid)
end

#world_readable?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/ru/file.rb', line 72

def world_readable?
  delegate_to_stat(:world_readable?)
end