class PhotoHelper::Delete

Public Instance Methods

jpeg(folder = nil) click to toggle source
# File lib/photo-helper/delete.rb, line 17
def jpeg(folder = nil)
  folder ||= options[:folder]
  puts folder

  search_path = File.expand_path(folder)
  jpeg_path = File.join(search_path, 'jpegs')

  files =
    if options[:recursive]
      Dir["#{search_path}/**/*.{#{JPEG_EXTENSIONS.join(',')}}"]
    else
      Dir["#{search_path}/*.{#{JPEG_EXTENSIONS.join(',')}}"]
    end

  files.each do |file|
    has_raw = false
    RAW_EXTENSIONS.each do |extension|
      raw_file_name = "#{File.basename(file.to_s, '.*')}.#{extension}"
      has_raw = true if File.exist? File.join(File.dirname(file.to_s), raw_file_name)
    end
    next unless has_raw
    next if FileHelper.ingore_file?(file)
    puts file

    if options[:softdelete]
      File.trash(file)
    else
      File.delete(file)
    end
  end

  return unless File.exist?(jpeg_path) && yes?('Delete jpeg folder?')
  say 'Deleting jpeg folder', :red
  if options[:hard]
    File.delete(jpeg_path)
  else
    File.trash(jpeg_path)
  end
end