Class: Sortobot::Helper
- Inherits:
-
Object
- Object
- Sortobot::Helper
- 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 |
.makedir ⇒ Object
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 |
.move ⇒ Object
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 |
.trim ⇒ Object
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 |