Class: Sortme::Sort

Inherits:
Object
  • Object
show all
Defined in:
lib/sortme.rb

Instance Method Summary collapse

Instance Method Details

#get_all_pathsObject



19
20
21
# File 'lib/sortme.rb', line 19

def get_all_paths
  Path.get
end

#get_path(file) ⇒ Object



23
24
25
26
27
28
29
30
# 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) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# 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

#startObject



6
7
8
9
10
11
12
13
14
15
16
17
# 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