downloads_sorter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83fda5b9acf3a03419dc03f3fb96e5611722cae6
4
+ data.tar.gz: d863f259b8b81d4c14f1afb3273fbf563668174b
5
+ SHA512:
6
+ metadata.gz: a0343432f570685f5cc6d49f69f9ac9e737f5f6a2af32ac3ff2c83b4c31f52ce51d9d3f0684691d2c99ad58efa0394ea4c780f0c941a703cfa1e9751da72f14f
7
+ data.tar.gz: a5e6bbd229a3e0b066c7c37d6b3ea3d9406842f271c9cb75645236c9db63ac26e453caebf9229b0c93345ce32a229980638fe5755f98a741a7f43eac5b9f0b65
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /tmp
16
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in downloads_sorter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kavinder Dhaliwal
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # DownloadsSorter
2
+
3
+ Ahhhhhhh! My downloads folder has about 10,000 files in it. It's such a mess. I don't want to manually go through this so I'll use the might DownloadsSorter gem to do that for me.
4
+
5
+ This gem goes through a specified folder (I build this for my Downloads folder, but could be anything) and moves certain file types to file types. This means PDFs and Docs go to a Documents folder, PNGs and JPEGS to an Images folder and so on.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'downloads_sorter'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install downloads_sorter
22
+
23
+ ## Usage
24
+
25
+ From your command line call `dl_sort` and a file path to sort:
26
+
27
+ ```ruby
28
+ dl_sort /Users/Me/Downloads
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/[my-github-username]/downloads_sorter/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/dl_sort ADDED
@@ -0,0 +1,11 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'downloads_sorter'
4
+
5
+ if ARGV[0]
6
+ d = DownloadsSorter.new(ARGV[0])
7
+ d.sort
8
+ else
9
+ puts "Please Specify a Directory to Sort"
10
+ abort
11
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'downloads_sorter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "downloads_sorter"
8
+ spec.version = DownloadsSorter::VERSION
9
+ spec.authors = ["Kavinder Dhaliwal"]
10
+ spec.email = ["kavinderd@gmail.com"]
11
+ spec.summary = %q{Directory Organizer}
12
+ spec.description = %q{For those times when a directory becomes unruly with file types}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,3 @@
1
+ module DownloadsSorter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'fileutils'
2
+ class NoPathError < Exception; end;
3
+
4
+ class DownloadsSorter
5
+ VERSION = "0.0.1"
6
+ PATH = File.join(Dir.home, "Downloads")
7
+ Images = %w{ *.jpg *.png *.jpeg}
8
+ Documents = %w{ *.pdf *.doc *.docx *.txt}
9
+ Audio = %w{ *.mp3 }
10
+ Books = %w{ *.epub }
11
+ Apps = %w{ *.dmg }
12
+ SUB_DIRS = %w{ Images Documents Audio Books Apps}
13
+
14
+
15
+ attr_reader :dir_path
16
+ def initialize(dir_path)
17
+ raise NoPathError unless Dir.exists?(dir_path)
18
+ @dir_path = dir_path
19
+ check_or_create_dirs
20
+ end
21
+
22
+ def sort
23
+ Dir.chdir(@dir_path) do
24
+ SUB_DIRS.each do |dir|
25
+ move_files_to_sub_dir(dir, DownloadsSorter.const_get(dir))
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def check_or_create_dirs
33
+ SUB_DIRS.each do |dir|
34
+ unless Dir.exists?(File.join(dir_path, dir))
35
+ Dir.mkdir(File.join(dir_path, dir))
36
+ end
37
+ end
38
+ end
39
+
40
+ def move_files_to_sub_dir(path, types)
41
+ files = types.map { |type| Dir.glob(type) }.flatten
42
+ if files.any?
43
+ files.each do |file|
44
+ FileUtils.mv(file, path)
45
+ end
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,51 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/downloads_sorter.rb'
3
+ class DownloadsSorterTest < MiniTest::Test
4
+ TEST_PATH = File.join("tmp", "Downloads")
5
+
6
+ def setup
7
+ unless Dir.exists?("tmp")
8
+ Dir.mkdir("tmp")
9
+ end
10
+ unless Dir.exists?(TEST_PATH)
11
+ Dir.mkdir(TEST_PATH)
12
+ end
13
+ seed_folder
14
+ end
15
+
16
+ def teardown
17
+ Dir.chdir(TEST_PATH) do
18
+ `rm -rf Images` if Dir.exists?('Images')
19
+ `rm -rf Documents` if Dir.exists?('Documents')
20
+ `rm -rf Audio` if Dir.exists?('Audio')
21
+ end
22
+ end
23
+
24
+ def seed_folder
25
+ Dir.chdir(TEST_PATH) do
26
+ %w{ file1.png file2.pdf file3.jpeg file4.txt file5.docx file6.xlsx file7.csv file.dump file.mp3 file.mp4 }.each do |file|
27
+ File.new(file, 'w+')
28
+ end
29
+ end
30
+ end
31
+
32
+ def test_finds_the_downloads_folder
33
+ ds = DownloadsSorter.new(TEST_PATH)
34
+ assert_equal(TEST_PATH, ds.dir_path)
35
+ end
36
+
37
+ def test_raises_error_if_no_downloads
38
+ assert_raises(NoPathError) { DownloadsSorter.new("tmp/Uploads") }
39
+ end
40
+
41
+ def test_moves_files_to_respective_directories
42
+ ds = DownloadsSorter.new(TEST_PATH)
43
+ ds.sort
44
+ assert(true, File.exists?("tmp/Downloads/Images/file1.png"))
45
+ assert(true, File.exists?("tmp/Downloads/Documents/file5.docx"))
46
+ Dir.chdir(TEST_PATH) do
47
+ assert(1, Dir.glob("*").count)
48
+ end
49
+ end
50
+
51
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: downloads_sorter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kavinder Dhaliwal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: For those times when a directory becomes unruly with file types
42
+ email:
43
+ - kavinderd@gmail.com
44
+ executables:
45
+ - dl_sort
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/dl_sort
55
+ - downloads_sorter.gemspec
56
+ - lib/downloads_sorter.rb
57
+ - lib/downloads_sorter/version.rb
58
+ - test/download_sorter_test.rb
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Directory Organizer
83
+ test_files:
84
+ - test/download_sorter_test.rb