AbsoluteRenamer 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{AbsoluteRenamer}
8
- s.version = "1.0.4"
8
+ s.version = "1.1.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-10-05}
12
+ s.date = %q{2009-11-02}
13
13
  s.default_executable = %q{absrenamer}
14
14
  s.description = %q{AbsoluteRenamer is a very powerful tool that helps files and directories renaming using the Krename syntax. Unlike many batch renaming tools, AbsoluteRenamer is able to rename folders. AbsoluteRenamer is modular and can be extended to adapt itself to any kind of file or to add new options and features.}
15
15
  s.email = %q{happynoff@free.fr}
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 1.1.0
@@ -1,31 +1,39 @@
1
1
  module AbsoluteRenamer
2
2
  class GeneralModule < AbsoluteRenamer::IModule
3
3
  def initialize
4
- @actions = {'*' => :file_camelize,
5
- '$' => :file_original,
6
- '%' => :file_downcase,
7
- '&' => :file_upcase,
8
- '\\' => :file_strip,
9
- '#' => :count
10
- }
11
-
12
- @case_filters = ['(\\\\\*)', # \*
13
- '(\\\\\$)', # \$
14
- '(\\\%)', # \%
15
- '(\\\&)', # \&
16
- '(\\\\\\\)', # \\
17
- '(\*)', # *
18
- '(\$)', # $
19
- '(%)', # %
20
- '(&)', # &
21
- '(\\\)' # \
22
- ]
4
+ @actions = {
5
+ '*' => :file_camelize,
6
+ '$' => :file_original,
7
+ '%' => :file_downcase,
8
+ '&' => :file_upcase,
9
+ '\\' => :file_strip,
10
+ '#' => :count
11
+ }
12
+
13
+ @case_filters = [
14
+ /\\\*/, # \*
15
+ /\\\$/, # \$
16
+ /\\%/, # \%
17
+ /\\&/, # \&
18
+ /\\\\/, # \\
19
+ /\*/, # *
20
+ /\$/, # $
21
+ /%/, # %
22
+ /&/, # &
23
+ /\\/ # \
24
+ ]
23
25
 
24
26
  # matches strings like [42-43] [42-] [*42-43] [42;43] etc...
25
- @part_filters = ['(\[(.)?(\d+)(((-)(\d+)?)|((;)(\d+)))?\])']
27
+ @part_filters = [
28
+ pattern('(\d+)((-(\d+)?)|(;\d+))?')
29
+ ]
26
30
 
27
31
  # matches counters like # ### #{2} ##{2;42} or [length-42]
28
- @misc_filters = ['(/)', '(#+(\{.*\})?)', '(\[length(--?\d+)?\])']
32
+ @misc_filters = [
33
+ /\//,
34
+ /#+(\{.*\})?/,
35
+ /\[length(--?\d+)?\]/
36
+ ]
29
37
 
30
38
  @filters = @case_filters + @part_filters + @misc_filters
31
39
  end
@@ -67,7 +75,6 @@ module AbsoluteRenamer
67
75
  def file_part(file, infos, type)
68
76
  matched = infos[0].match(/(\[([^\d])?(\d+)(((;)(\d+))|((-)(\d+)?))?\])/)
69
77
 
70
- modifier = matched[2]
71
78
  x = matched[3].to_i - 1
72
79
  y = matched[7] || matched[10]
73
80
  y = y.to_i unless y.nil?
@@ -87,11 +94,7 @@ module AbsoluteRenamer
87
94
 
88
95
  val ||= ''
89
96
 
90
- unless modifier.nil?
91
- mp = CaseModule.method(CaseModule.actions[modifier])
92
- val = mp.call(val)
93
- end
94
- val
97
+ modify val, matched[2]
95
98
  end
96
99
 
97
100
  def count(file, infos, type)
@@ -14,7 +14,7 @@ module AbsoluteRenamer
14
14
  include AbsoluteRenamer::UseConfig
15
15
 
16
16
  def load_gems
17
- if Gem
17
+ if defined?(Gem)
18
18
  @gems = {}
19
19
 
20
20
  find_gems
@@ -22,6 +22,7 @@ module AbsoluteRenamer
22
22
  exclude_gems
23
23
 
24
24
  @gems.each do |gem_name, gem_infos|
25
+ puts "Loading gem #{gem_name} (#{gem_infos[:version]}) : #{gem_infos[:lib]}" if conf[:debug]
25
26
  gem gem_name, gem_infos[:version]
26
27
  require gem_infos[:lib]
27
28
  end
@@ -40,9 +40,15 @@ module AbsoluteRenamer
40
40
  end
41
41
 
42
42
  # Displays the action that will be done on the file.
43
- # some_fileinfo.display_change # => "rename a_file.txt --> A_File.TXT"
43
+ # some_fileinfo.display_change # => "rename a_file.txt --> A_File.TXT"
44
44
  def display_change
45
- puts "#{conf[:options][:mode]} #{@real_path.sub(Dir.pwd+'/', '')} --> #{new_path.sub(Dir.pwd+'/', '')}"
45
+ puts "#{color conf[:options][:mode]} #{@real_path.sub(Dir.pwd+'/', '')} #{color '-->'} #{new_path.sub(Dir.pwd+'/', '')}"
46
+ end
47
+
48
+ # Returns a text colorized in red.
49
+ # color('hello') #=> "\e[31mhello\e[0m"
50
+ def color(text)
51
+ "\e[31m#{text}\e[0m"
46
52
  end
47
53
 
48
54
  # Returns the new path of the file.
@@ -13,6 +13,24 @@ module AbsoluteRenamer
13
13
  name.intern
14
14
  end
15
15
 
16
+ # Returns a format pattern generated from pattern_string that
17
+ # can be used to match strings like [*test] in the filename format
18
+ # pattern('test') #=> '(\[(.)?test\])'
19
+ def pattern(pattern_string)
20
+ Regexp.new "(\\[(.)?#{pattern_string}\\])"
21
+ end
22
+
23
+ # Returns a value modified using a modifier defined in the Case module
24
+ # modifiy('value', '&') #=> 'VALUE'
25
+ # modifiy('value', '*') #=> 'Value'
26
+ def modify(val, modifier)
27
+ if CaseModule.actions.include?(modifier)
28
+ mod = CaseModule.method(CaseModule.actions[modifier])
29
+ val = mod.call(val)
30
+ end
31
+ val
32
+ end
33
+
16
34
  # Process a +file+ by searching for a known pattern in its name
17
35
  # and replacing it by the corresponding value.
18
36
  # The pattern is a regular expression obtained by concatening
@@ -26,11 +44,11 @@ module AbsoluteRenamer
26
44
 
27
45
  str = format
28
46
  result = []
29
- pattern = Regexp.new(@filters.join('|'))
47
+ pattern = Regexp.union @filters
30
48
 
31
49
  idx = str.index(pattern)
32
50
  while idx
33
- matched = pattern.match(str).to_a.compact
51
+ matched = pattern.match(str).to_a
34
52
  part = str.partition(matched[0])
35
53
  result.push(part[0])
36
54
  val = self.interpret(file, matched, type)
@@ -33,6 +33,10 @@ class FileInfoTest < Test::Unit::TestCase
33
33
  assert_equal(false, @fileinfo.dir)
34
34
  end
35
35
 
36
+ should "be able to return a colorized string" do
37
+ assert_equal("\e[31mhello\e[0m", @fileinfo.color('hello'))
38
+ end
39
+
36
40
  end
37
41
 
38
42
  context "loaded with lib/absolute_renamer" do
data/test/imodule_test.rb CHANGED
@@ -40,6 +40,29 @@ class IModuleTest < Test::Unit::TestCase
40
40
  assert_equal(@default_string, @imodule.interpret(@fileinfo, @infos, :ext))
41
41
  end
42
42
 
43
+ should "be able to build a pattern from a pattern_string" do
44
+ assert_equal(/(\[(.)?test\])/, @imodule.pattern('test'))
45
+ end
46
+
47
+ context "and core modules loaded" do
48
+
49
+ setup do
50
+ AbsoluteRenamer::External.load_core
51
+ end
52
+
53
+ should "be able to return a string transformed with a case modifier" do
54
+ assert_equal("Hello World", @imodule.modify("heLLo wORLd", "*"))
55
+ end
56
+
57
+ should "return the original value if a non existing modifier is passed to modify" do
58
+ assert_equal("Hello World", @imodule.modify("Hello World", "x"))
59
+ end
60
+
61
+ should "return the original value if a nil modifier is passed to modify" do
62
+ assert_equal("Hello World", @imodule.modify("Hello World", nil))
63
+ end
64
+ end
65
+
43
66
  end
44
67
  end
45
68
  end
data/test/string_test.rb CHANGED
@@ -19,14 +19,6 @@ class LibStringTest < Test::Unit::TestCase
19
19
  assert_equal("Hello..World", "hello..world".camelize)
20
20
  end
21
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
22
  context "set to hello world" do
31
23
 
32
24
  setup do
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: 1.0.4
4
+ version: 1.1.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-10-05 00:00:00 +02:00
12
+ date: 2009-11-02 00:00:00 +01:00
13
13
  default_executable: absrenamer
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency