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



86
87
88
# File 'lib/ru/file.rb', line 86

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
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

#modeObject



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

def mode
  delegate_to_stat(:mode)
end

#mtimeObject Also known as: updated_at



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

def mtime
  delegate_to_file(:mtime)
end

#omodeObject



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

def omode
  '%o' % world_readable?
end

#ownerObject



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

#sizeObject



70
71
72
# File 'lib/ru/file.rb', line 70

def size
  delegate_to_file(:size)
end

#to_sObject



74
75
76
# File 'lib/ru/file.rb', line 74

def to_s
  name
end

#uidObject



78
79
80
# File 'lib/ru/file.rb', line 78

def uid
  delegate_to_stat(:uid)
end

#world_readable?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/ru/file.rb', line 82

def world_readable?
  delegate_to_stat(:world_readable?)
end