class Eax::EaxFile
Attributes
path_name[RW]
type[RW]
Public Class Methods
new(file)
click to toggle source
# File lib/eax.rb, line 72 def initialize(file) @path_name = Pathname.new(file) @type = file_type(@path_name) end
Public Instance Methods
color()
click to toggle source
# File lib/eax.rb, line 77 def color @color ||= Pastel.new end
output(options)
click to toggle source
# File lib/eax.rb, line 81 def output(options) if options.long? [print_rights, print_size(bytes: options.bytes?), print_user(group: options.group?), choose_date_to_print(options), print_name ] else [print_name] end.join(' ') end
Private Instance Methods
choose_date_to_print(options)
click to toggle source
# File lib/eax.rb, line 137 def choose_date_to_print(options) stat = path_name.stat if options.modified? print_date stat.mtime else print_date stat.ctime end end
determine_right(number)
click to toggle source
# File lib/eax.rb, line 103 def determine_right(number) right = '' {4 => color.dim.yellow('r'), 2 => color.red('w'), 1 => color.green('x'), 0 => '-'}.each { |key, value| compar = number - key if compar >= 0 right += value else right += '-' next end number = compar } right[0..-2] end
file_type(path_name)
click to toggle source
# File lib/eax.rb, line 150 def file_type(path_name) return FileTypes::FolderType.new if path_name.directory? return FileTypes::ExecutableType.new if path_name.executable? return FileTypes::ImportantType.new if %w(README.md Gemfile Grunt.js).include? path_name.basename.to_s case path_name.extname when 'jpeg', 'jpg', 'gif', 'svg', 'bitmap' FileTypes::ImageType.new else FileTypes::NormalType.new end end
print_date(date)
click to toggle source
# File lib/eax.rb, line 133 def print_date(date) color.blue date.strftime("%d %b %H:%M") end
print_name()
click to toggle source
# File lib/eax.rb, line 146 def print_name type.output(path_name.basename) end
print_rights(group: false)
click to toggle source
# File lib/eax.rb, line 92 def print_rights(group: false) mode = path_name.stat.mode.to_s(8) folder = mode[0] == '4' ? color.blue('d') : '.' user = mode[-3].to_i group = mode[-2].to_i other = mode[-1].to_i rights = [folder, color.bold(determine_right(user))] rights << determine_right(group) << determine_right(other) if group rights.join end
print_size(bytes: false)
click to toggle source
# File lib/eax.rb, line 119 def print_size(bytes: false) return ' ' * 5 + '-' if path_name.directory? size = path_name.stat.size return color.green.bold size.to_s if bytes size_in_word = Filesize.from("#{size} B").pretty.gsub(/\.00/, '').gsub(' ', '').gsub(/B/, '') color.green.bold(' ' * (6 - size_in_word.length) + size_in_word ) end
print_user(group: false)
click to toggle source
# File lib/eax.rb, line 127 def print_user(group: false) user = color.yellow.bold(Etc.getpwuid(path_name.stat.uid).name) user += color.yellow(' ' + Etc.getgrgid(path_name.stat.gid).name) if group user end