sortobot 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,7 +19,11 @@ Or install it yourself as:
19
19
  ## Usage
20
20
  To push group files of the directory into subdirectory based on file-type.
21
21
 
22
- sortobot push
22
+ sortobot push
23
+
24
+ To Remove empty directories.
25
+
26
+ sortobot trim
23
27
 
24
28
  ## Contributing
25
29
 
@@ -0,0 +1,20 @@
1
+ require 'fileutils'
2
+
3
+ module Sortobot
4
+ class Helper
5
+ Directories = {"text" => "Documents", "image" =>"Images", "audio"=>"Music", "video"=>"Videos"}
6
+
7
+ def self.associate(file)
8
+ type = MIME::Types.type_for(file).first.media_type rescue nil
9
+ return Directories[type]
10
+ end
11
+
12
+ def self.makedir
13
+ Directories.each_value do |directory|
14
+ unless Dir.exists? directory
15
+ FileUtils.mkdir(directory)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Sortobot
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/sortobot.rb CHANGED
@@ -2,38 +2,29 @@ require "mime/types"
2
2
  require "thor"
3
3
  require "thor/group"
4
4
  require "fileutils"
5
+ require "sortobot/helper"
5
6
 
6
7
  module Sortobot
7
8
  class Cli < Thor
8
- Directories = {"text" => "Documents", "image" =>"Images", "audio"=>"Music"}
9
- #<Helpers>
10
- def self.associate(file)
11
- type = MIME::Types.type_for(file).first
12
-
13
- if type
14
- if Directories.has_key? type.media_type
15
- return Directories[type.media_type]
16
- end
17
- end
18
- end
19
-
20
- def self.makedir
21
- Directories.each_value do |directory|
22
- unless Dir.exists? directory
23
- FileUtils.mkdir(directory)
24
- end
25
- end
26
- end
27
- #</Helpers>
28
-
29
9
  desc "push", "push files into directories"
30
10
  def push
31
- Cli.makedir
32
- Dir.open(Dir.pwd).each do |file|
33
- if Cli.associate(file)
34
- FileUtils.mv(file, Cli.associate(file))
11
+ Helper.makedir
12
+ Dir.foreach(Dir.pwd) do |file|
13
+ if Helper.associate(file)
14
+ FileUtils.mv(file, Helper.associate(file))
35
15
  end
36
16
  end
37
17
  end
38
- end
18
+
19
+ desc "trim", "removes empty directories"
20
+ def trim
21
+ Dir.foreach(Dir.pwd) do |entry|
22
+ if File.directory? entry
23
+ if Dir.entries(entry).join == "..."
24
+ FileUtils.rmdir entry
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
39
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-02 00:00:00.000000000 Z
12
+ date: 2012-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &80857030 !ruby/object:Gem::Requirement
16
+ requirement: &84571080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *80857030
24
+ version_requirements: *84571080
25
25
  description: A CLI tool for organizing files in a directory
26
26
  email:
27
27
  - mohanr2222@gmail.com
@@ -37,9 +37,9 @@ files:
37
37
  - Rakefile
38
38
  - bin/sortobot
39
39
  - lib/sortobot.rb
40
+ - lib/sortobot/helper.rb
40
41
  - lib/sortobot/version.rb
41
42
  - sortobot.gemspec
42
- - sortobot.thor
43
43
  homepage: ''
44
44
  licenses: []
45
45
  post_install_message:
data/sortobot.thor DELETED
@@ -1,39 +0,0 @@
1
- require "mime/types"
2
- require "thor"
3
- require "thor/group"
4
- require "fileutils"
5
-
6
- module Sortobot
7
- class Cli < Thor
8
- Directories = {"text" => "Documents", "image" =>"Images", "audio"=>"Music"}
9
- #<Helpers>
10
- def self.associate(file)
11
- type = MIME::Types.type_for(file).first
12
-
13
- if type
14
- if Directories.has_key? type.media_type
15
- return Directories[type.media_type]
16
- end
17
- end
18
- end
19
-
20
- def self.makedir
21
- Directories.each_value do |directory|
22
- unless Dir.exists? directory
23
- FileUtils.mkdir(directory)
24
- end
25
- end
26
- end
27
- #</Helpers>
28
-
29
- desc "push", "push files into directories"
30
- def push
31
- Cli.makedir
32
- Dir.open(Dir.pwd).each do |file|
33
- if Cli.associate(file)
34
- FileUtils.mv(file, Cli.associate(file))
35
- end
36
- end
37
- end
38
- end
39
- end