Class: Sortobot::Helper

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

Constant Summary collapse

Directories =
{"text" => "Documents", "image" =>"Images", "audio"=>"Music", "video"=>"Videos"}

Class Method Summary collapse

Class Method Details

.associate(file) ⇒ Object



7
8
9
10
# File 'lib/sortobot/helper.rb', line 7

def self.associate(file)
	type = MIME::Types.type_for(file).first.media_type rescue nil
	return Directories[type]
end

.makedirObject



12
13
14
15
16
# File 'lib/sortobot/helper.rb', line 12

def self.makedir
	Directories.each_value do |directory|
		FileUtils.mkdir(directory) unless Dir.exists? directory								
	end
end

.moveObject



28
29
30
31
32
33
34
# File 'lib/sortobot/helper.rb', line 28

def self.move
	Dir.foreach(Dir.pwd) do |file|
		if associate(file)
			FileUtils.mv(file, associate(file))		
		end	
	end			
end

.trimObject



18
19
20
21
22
23
24
25
26
# File 'lib/sortobot/helper.rb', line 18

def self.trim
	Dir.foreach(Dir.pwd) do |entry|
		if File.directory? entry
			if Dir.entries(entry).join == "..."
				FileUtils.rmdir entry
			end
		end
	end			
end