AbsoluteRenamer 0.9.2 → 0.10.0

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.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{AbsoluteRenamer}
8
- s.version = "0.9.2"
8
+ s.version = "0.10.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Simon COURTOIS"]
12
- s.date = %q{2009-09-22}
12
+ s.date = %q{2009-09-29}
13
13
  s.default_executable = %q{absrenamer}
14
14
  s.description = %q{Unlike many batch renaming tools, AbsoluteRenamer is able to rename folders.
15
15
  AbsoluteRenamer is modular and can be extended to adapt itself to any kind of file
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  "lib/absolute_renamer/iparser.rb",
46
46
  "lib/absolute_renamer/iplugin.rb",
47
47
  "lib/absolute_renamer/libs/file.rb",
48
+ "lib/absolute_renamer/libs/hash.rb",
48
49
  "lib/absolute_renamer/libs/string.rb",
49
50
  "lib/absolute_renamer/parser.rb",
50
51
  "lib/absolute_renamer/use_config.rb",
@@ -53,6 +54,11 @@ Gem::Specification.new do |s|
53
54
  "test/config_test.rb",
54
55
  "test/file_info_test.rb",
55
56
  "test/file_test.rb",
57
+ "test/hash_test.rb",
58
+ "test/imodule_test.rb",
59
+ "test/iplugin_test.rb",
60
+ "test/parser_test.rb",
61
+ "test/string_test.rb",
56
62
  "test/test_helper.rb"
57
63
  ]
58
64
  s.homepage = %q{http://github.com/simonc/AbsoluteRenamer}
@@ -65,6 +71,11 @@ Gem::Specification.new do |s|
65
71
  "test/config_test.rb",
66
72
  "test/file_info_test.rb",
67
73
  "test/file_test.rb",
74
+ "test/hash_test.rb",
75
+ "test/imodule_test.rb",
76
+ "test/iplugin_test.rb",
77
+ "test/parser_test.rb",
78
+ "test/string_test.rb",
68
79
  "test/test_helper.rb"
69
80
  ]
70
81
 
data/README.rdoc CHANGED
@@ -2,32 +2,31 @@
2
2
 
3
3
  AbsoluteRenamer is a very powerful tool that helps files and directories renaming using the Krename syntax.
4
4
 
5
- = SYNOPSIS:
5
+ == Synopsis
6
6
 
7
- absrenamer[OPTION]... [FILE]...
7
+ absrenamer [OPTION]... [FILE]...
8
8
 
9
- absrenamer-f 'photo_##' -x '%' IMG*.JPG
9
+ For instance, the following line will rename all IMG*.JPG files in photo_01.jpg, photo_02.jpg, ...
10
10
 
11
- = REQUIREMENTS:
11
+ absrenamer -f 'photo_##' -x '%' IMG*.JPG
12
+
13
+ == Requirements
12
14
 
13
15
  * Ruby >= 1.8.7 (earlier releases will not work)
14
16
 
15
- = INSTALL:
17
+ == Installing
16
18
 
17
19
  You can simply install AbsoluteRenamer with gem :
18
20
 
19
- sudo gem install simonc-AbsoluteRenamer
20
-
21
- == Note on Patches/Pull Requests
22
-
23
- * Fork the project.
24
- * Make your feature addition or bug fix.
25
- * Add tests for it. This is important so I don't break it in a
26
- future version unintentionally.
27
- * Commit, do not mess with rakefile, version, or history.
28
- (if you want to have your own version, that is fine but
29
- bump version in a commit by itself I can ignore when I pull)
30
- * Send me a pull request. Bonus points for topic branches.
21
+ sudo gem install simonc-AbsoluteRenamer
22
+
23
+ == Documentation
24
+
25
+ * http://wiki.github.com/simonc/AbsoluteRenamer
26
+
27
+ == Contributors
28
+
29
+ * Simon COURTOIS
31
30
 
32
31
  == Copyright
33
32
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.10.0
data/bin/absrenamer CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby187
2
2
 
3
3
  #
4
4
  # = Synopsis
@@ -30,6 +30,12 @@
30
30
  # = Copyright (c) 2009 Simon COURTOIS
31
31
  # Licensed under the GNU Public License
32
32
 
33
+ # Checking the ruby version.
34
+ unless RUBY_VERSION >= "1.8.7"
35
+ $stderr.puts "AbsoluteRenamer must be used with Ruby >= 1.8.7"
36
+ exit 1
37
+ end
38
+
33
39
  $:.unshift File.dirname(__FILE__) << '/../lib'
34
40
 
35
41
  require 'absolute_renamer'
@@ -38,10 +44,11 @@ require 'absolute_renamer/parser'
38
44
  require 'absolute_renamer/external'
39
45
 
40
46
  config_path = File.dirname(__FILE__)+'/../conf/absrenamer/absrenamer.conf'
41
- config_path = '/etc/absrenamer/absrenamer.conf' if File.exists?('/etc/absrenamer/absrenamer.conf')
47
+ global_conf = '/etc/absrenamer/absrenamer.conf'
42
48
  custom_conf = '~/.absrenamerrc'
43
49
 
44
50
  AbsoluteRenamer::Config.load(config_path)
51
+ AbsoluteRenamer::Config.load(global_conf) if File.exists? global_conf
45
52
  AbsoluteRenamer::Config.load(custom_conf) if File.exists? custom_conf
46
53
 
47
54
  AbsoluteRenamer::Parser.parse_cmd_line
@@ -7,7 +7,11 @@ module AbsoluteRenamer
7
7
  # Open and load a Yaml file into the +@conf+ variable.
8
8
  # config_path: path of the file to load.
9
9
  def load(config_path)
10
- @conf = YAML::load_file(config_path)
10
+ @conf ||= {}
11
+
12
+ if tmp_conf = YAML::load_file(config_path)
13
+ @conf.deep_merge! tmp_conf
14
+ end
11
15
 
12
16
  @conf[:options] ||= {}
13
17
  @conf[:options][:format] ||= '$'
@@ -0,0 +1,28 @@
1
+ # Extension of existing Hash class
2
+ class Hash
3
+ # Returns a new hash containing resulting of a recursive merge between two hashes
4
+ # new_hash: the hash to merge
5
+ # h1 = { :key1 => :val1, :key2 => { :key21 => :val21 } }
6
+ # h2 = { :key2 => { :key22 => :val22 }, :key3 => val3 }
7
+ # h1.deep_marge! h2 #=> { :key1 => val1, :key2 => { :key21 => :val21. :key22 => :val22 }, test3 => val3 }
8
+ # h1 #=> { :key1 => :val1, :key2 => { :key21 => :val21 } }
9
+ def deep_merge(new_hash)
10
+ self.clone.deep_merge! new_hash
11
+ end
12
+
13
+ # Adds the contents of new_hash to another hash recusively
14
+ # new_hash: the hash to merge
15
+ # h1 = { :key1 => :val1, :key2 => { :key21 => :val21 } }
16
+ # h2 = { :key2 => { :key22 => :val22 }, :key3 => val3 }
17
+ # h1.deep_marge! h2
18
+ # h1 #=> { :key1 => val1, :key2 => { :key21 => :val21. :key22 => :val22 }, test3 => val3 }
19
+ def deep_merge!(new_hash)
20
+ merge! new_hash do |key, v1, v2|
21
+ if v1.is_a? Hash
22
+ v1.deep_merge! v2
23
+ else
24
+ self[key] = v2
25
+ end
26
+ end
27
+ end
28
+ end
@@ -12,9 +12,9 @@ class String
12
12
 
13
13
  # Camelizes a string and returns it.
14
14
  # str = "Hello.THE World"
15
- # str.camelize! # => "Hello.The World"
16
- # str.camelize!(/[\.]/) # => "Hello.The World"
17
- # str # => "Hello.The World"
15
+ # str.camelize! # => "Hello.The World"
16
+ # str.camelize!(/[\.]/) # => "Hello.The World"
17
+ # str # => "Hello.The World"
18
18
  def camelize!(word_separators = /[\W_]/)
19
19
  self.downcase!
20
20
  self.each_char.each_with_index do |c,i|
@@ -8,6 +8,7 @@ require 'absolute_renamer/parser'
8
8
  require 'absolute_renamer/file_info'
9
9
  require 'absolute_renamer/libs/file'
10
10
  require 'absolute_renamer/libs/string'
11
+ require 'absolute_renamer/libs/hash'
11
12
  require 'absolute_renamer/use_config'
12
13
 
13
14
  # top level module of AbsoluteRenamer.
data/test/hash_test.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ class LibHashTest < Test::Unit::TestCase
4
+ context "A Hash instance" do
5
+
6
+ setup do
7
+ @hash1 = { :key1 => :val1, :key2 => { :key21 => :val21 } }
8
+ @hash2 = { :key2 => { :key22 => :val22 }, :key3 => :val3 }
9
+ @hash3 = { :key1 => :val12 }
10
+
11
+ @result1 = { :key1 => :val1, :key2 => { :key21 => :val21, :key22 => :val22 }, :key3 => :val3 }
12
+ @result2 = { :key1 => :val12, :key2 => { :key21 => :val21 } }
13
+ end
14
+
15
+ should "be able to merge recursively with another without changing" do
16
+ assert_equal @hash1.deep_merge(@hash2), @result1
17
+ assert_not_equal @hash1, @result
18
+ end
19
+
20
+ should "be able to merge recursively with another" do
21
+ @hash1.deep_merge! @hash2
22
+ assert_equal @hash1, @result1
23
+ end
24
+
25
+ should "be able to simply merge with another" do
26
+ @hash1.deep_merge! @hash3
27
+ assert_equal @hash1, @result2
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ class IModuleTest < Test::Unit::TestCase
4
+ context "The IModule class" do
5
+
6
+ should "be able to return its symbol" do
7
+ assert_equal(:"AbsoluteRenamer::IModule", AbsoluteRenamer::IModule.symbol)
8
+ end
9
+
10
+ end
11
+
12
+ context "An IModule instance" do
13
+
14
+ setup do
15
+ @imodule = AbsoluteRenamer::IModule.new
16
+ @fileinfo = AbsoluteRenamer::FileInfo.new('/some/path/to/a_file.txt')
17
+ end
18
+
19
+ should "set the right filename format when calling process" do
20
+ assert_equal('format', @imodule.process(@fileinfo, 'format', :name))
21
+ end
22
+
23
+ should "set the right extension format when calling process" do
24
+ assert_equal('format', @imodule.process(@fileinfo, 'format', :ext))
25
+ end
26
+
27
+ context "with config file loaded" do
28
+
29
+ setup do
30
+ AbsoluteRenamer::Config.load('conf/absrenamer/absrenamer.conf')
31
+ @default_string = AbsoluteRenamer::Config[:options][:default_string]
32
+ @infos = [nil, nil, '', 'matched']
33
+ end
34
+
35
+ should "be able to interpret a matching result for filename" do
36
+ assert_equal(@default_string, @imodule.interpret(@fileinfo, @infos, :name))
37
+ end
38
+
39
+ should "be able to interpret a matching result for extension" do
40
+ assert_equal(@default_string, @imodule.interpret(@fileinfo, @infos, :ext))
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class IPluginTest < Test::Unit::TestCase
4
+ context "The IPlugin class" do
5
+
6
+ should "be able to return its symbol" do
7
+ assert_equal(:"AbsoluteRenamer::IPlugin", AbsoluteRenamer::IPlugin.symbol)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class ParserTest < Test::Unit::TestCase
4
+ context "A Parser instance" do
5
+
6
+ context "with config file loaded and the -f'format' option set" do
7
+
8
+ setup do
9
+ AbsoluteRenamer::Config.load('conf/absrenamer/absrenamer.conf')
10
+ ARGV << '-f'
11
+ ARGV << 'format'
12
+ end
13
+
14
+ should "be able to parse the format from the command line options" do
15
+ AbsoluteRenamer::Parser.parse_cmd_line
16
+ assert_equal('format', AbsoluteRenamer::Config[:options][:format])
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ class LibStringTest < Test::Unit::TestCase
4
+ context "A String instance" do
5
+
6
+ should "return Hello World when camelizing hello world" do
7
+ assert_equal("Hello World", "hello world".camelize)
8
+ end
9
+
10
+ should "return Hello.World when camelizing hello.world" do
11
+ assert_equal("Hello.World", "hello.world".camelize)
12
+ end
13
+
14
+ should "return Hello The.World when camelizing hello THE.world" do
15
+ assert_equal("Hello The.World", "hello THE.world".camelize)
16
+ end
17
+
18
+ should "return Hello..World when camelizing hello..world" do
19
+ assert_equal("Hello..World", "hello..world".camelize)
20
+ end
21
+
22
+ should "return Hello.World when camelizing hello.world with the /\./ separation pattern" do
23
+ assert_equal("Hello.World", "hello.world".camelize(/\./))
24
+ end
25
+
26
+ should "return Hello The.world when camelizing hello THE.world with the / / separation pattern" do
27
+ assert_equal("Hello The.world", "hello THE.world".camelize(/ /))
28
+ end
29
+
30
+ context "set to hello world" do
31
+
32
+ setup do
33
+ @string = 'hello world'
34
+ end
35
+
36
+ should "return and be equal to Hello World when calling camelize!" do
37
+ assert_equal("Hello World", @string.camelize!)
38
+ assert_equal("Hello World", @string)
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
data/test/test_helper.rb CHANGED
@@ -5,6 +5,8 @@ require 'shoulda'
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
7
  require 'absolute_renamer'
8
+ require 'absolute_renamer/libs/string'
9
+ require 'absolute_renamer/libs/file'
8
10
 
9
11
  class Test::Unit::TestCase
10
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: AbsoluteRenamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon COURTOIS
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-22 00:00:00 +02:00
12
+ date: 2009-09-29 00:00:00 +02:00
13
13
  default_executable: absrenamer
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -59,6 +59,7 @@ files:
59
59
  - lib/absolute_renamer/iparser.rb
60
60
  - lib/absolute_renamer/iplugin.rb
61
61
  - lib/absolute_renamer/libs/file.rb
62
+ - lib/absolute_renamer/libs/hash.rb
62
63
  - lib/absolute_renamer/libs/string.rb
63
64
  - lib/absolute_renamer/parser.rb
64
65
  - lib/absolute_renamer/use_config.rb
@@ -67,6 +68,11 @@ files:
67
68
  - test/config_test.rb
68
69
  - test/file_info_test.rb
69
70
  - test/file_test.rb
71
+ - test/hash_test.rb
72
+ - test/imodule_test.rb
73
+ - test/iplugin_test.rb
74
+ - test/parser_test.rb
75
+ - test/string_test.rb
70
76
  - test/test_helper.rb
71
77
  has_rdoc: true
72
78
  homepage: http://github.com/simonc/AbsoluteRenamer
@@ -101,4 +107,9 @@ test_files:
101
107
  - test/config_test.rb
102
108
  - test/file_info_test.rb
103
109
  - test/file_test.rb
110
+ - test/hash_test.rb
111
+ - test/imodule_test.rb
112
+ - test/iplugin_test.rb
113
+ - test/parser_test.rb
114
+ - test/string_test.rb
104
115
  - test/test_helper.rb