leran 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/leran +23 -0
  2. data/lib/leran.rb +73 -0
  3. metadata +47 -0
data/bin/leran ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ require 'leran'
3
+
4
+ # Initialize it!
5
+
6
+ if ARGV[0] == "help" || ARGV[0] == nil
7
+ puts %q{Use demonstration:
8
+ leran fromDir toDir [-d]
9
+
10
+ fromDir => the desorganized directory
11
+ toDir => the directory for to move the organized files
12
+
13
+ isDeep => find for archives in fromDir subfolders. For yes, use -d
14
+
15
+ Enjoy it!}
16
+ else
17
+ goNow = Leran.new ARGV[0],ARGV[1],ARGV[2]
18
+
19
+ puts "Organized files counter: #{goNow.totalMoveds}
20
+ Finished! \n -Script by Bill Hotter
21
+ Press Enter to close..."
22
+ STDIN.readline
23
+ end
data/lib/leran.rb ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+
4
+ class Leran
5
+ @@fileTypes = {
6
+
7
+ 'Video' =>
8
+ %w(.AVI .MKV .MP4 .MPEG .MPG .VOB .RMVB .WMV .FLV .MOV),
9
+
10
+ 'Music' =>
11
+ %w(.MP3 .AMR .WAV .WMA .ACC .OGG),
12
+
13
+ 'Img' =>
14
+ %w(.JPG .JPEG .BMP .PNG .GIF .ICO .PSD .XCF),
15
+
16
+ 'Docs' =>
17
+ %w(.ODT .DOC .DOCX .XLS .XLSX .PPSX .PPS .PDF),
18
+
19
+ 'Others' =>
20
+ %w(.TXT .RAR .ZIP .TAR .EXE .TORRENT)
21
+
22
+ }
23
+
24
+ @@types = @@fileTypes.keys
25
+
26
+ # Firt step: Get the 'from'/'to' folders
27
+ # def scanFolder: Find folders and files
28
+ # def moveFile: do... duhhhh
29
+
30
+ def initialize( fromDir, toDir, isDeep )
31
+ @qtMoveds = 0
32
+ toDir = fromDir if toDir == '-e'
33
+
34
+ puts '_' * 50
35
+ puts 'Entering in the store directory and creating folders'
36
+
37
+ scanFolder fromDir,toDir,isDeep
38
+ end
39
+
40
+ def scanFolder( from,to,deep )
41
+ Dir.foreach( from ) do |file|
42
+ if !File.directory? "#{from}/#{file}"
43
+ ext = File.extname( file ).upcase
44
+
45
+ moveFile from,to,file,ext if ext != ""
46
+ elsif deep == '-d' && !file =~ /^\.{1,2}/ # ignore dirs '.' and '..'
47
+ scanFolder( "#{from}/#{file}", to, '-d' ) if !(@@types.include? file)
48
+ end
49
+ end
50
+ end
51
+
52
+ def moveFile( from,to,file,ext )
53
+ @@fileTypes.each_key do | type |
54
+ if @@fileTypes[type].include? ext
55
+ puts "Moving: #{file.slice(0,20)}... | Type: #{type}"
56
+
57
+ # First: Create the folder for type
58
+ # Second: Create the folder for extension
59
+
60
+ Dir.mkdir( "#{to}/#{type}", 0755 ) if !File.exists? "#{to}/#{type}"
61
+ Dir.mkdir( "#{to}/#{type}/#{ext}", 0755 ) if !File.exists? "#{to}/#{type}/#{ext}"
62
+
63
+ FileUtils.mv "#{from}/#{file}", "#{to}/#{type}/#{ext}"
64
+ @qtMoveds += 1
65
+ end
66
+ end
67
+ end
68
+
69
+ def totalMoveds
70
+ @qtMoveds
71
+ end
72
+
73
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leran
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gabriel Rubens
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A simple File Organizer in Ruby
15
+ email: grsabreu@gmail.com
16
+ executables:
17
+ - leran
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/leran.rb
22
+ - bin/leran
23
+ homepage: http://rubygems.org/gems/leran
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.24
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Hola!
47
+ test_files: []