class Sortme::Sort

Public Instance Methods

get_all_paths() click to toggle source
# File lib/sortme.rb, line 19
def get_all_paths
  Path.get
end
get_path(file) click to toggle source
# File lib/sortme.rb, line 23
def get_path(file)
  paths = get_all_paths
  case File.extname(file)
  when ".png", ".jpg", ".gif" then paths["picture"]
  when ".flv", ".mp4", ".vob", ".avi" then paths["video"]
  when ".mp3", ".wma", ".wav" then paths["music"]
  end
end
media?(file) click to toggle source
# File lib/sortme.rb, line 32
def media?(file)
  extensions = [".png", ".gif", ".jpg", ".flv", ".mp4", ".vob", ".avi",
                ".mp3", ".wma", ".wav"]
  extensions.include? File.extname(file)
end
start() click to toggle source
# File lib/sortme.rb, line 6
def start
  home = File.expand_path("~")
  Path.set unless File.file?("#{home}/sortme_settings.json")
  count = 0
  Dir.foreach(".") do |file|
    if media?(file)
      path = get_path(file)
      count += 1 if system "mv \"#{file}\" #{path}"
    end
  end
  puts "#{count} files moved"
end