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
print_name() click to toggle source
print_rights(group: false) click to toggle source
print_size(bytes: false) click to toggle source
print_user(group: false) click to toggle source