Renamer 0.4.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.
@@ -0,0 +1,187 @@
1
+ =begin
2
+ Copyright (c) 2004-2006 by Nicolas Cavigneaux <nico@bounga.org>
3
+ See COPYING for License detail.
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the Free Software
17
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+ =end
19
+
20
+ # Class to handle a list of files to rename
21
+ include GetText
22
+
23
+ class Renamer
24
+ EXISTS = _("%s: The destination file already exists!") % Const::NAME
25
+
26
+ # Create a new Renamer object
27
+ def initialize(filenames, recursive = false)
28
+ # User wants to process files recursively
29
+ if recursive
30
+ @filenames = Array.new
31
+ filenames.each do |f|
32
+ if File.directory?(f)
33
+ @filenames << Dir.glob("#{f}/**/*")
34
+ else
35
+ @filenames << f
36
+ end
37
+ end
38
+ # In recursive mode we don't want to process directory names
39
+ @filenames.flatten!
40
+ @filenames.delete_if { |f| File.directory?(f) }
41
+ # User just wants to process given files
42
+ else
43
+ @filenames = filenames
44
+ end
45
+ end
46
+
47
+ # Downcase filenames
48
+ def downcase
49
+ proc_dc = Proc.new do |file|
50
+ new = file.downcase
51
+ rename_fs(file, new)
52
+ end
53
+ run(proc_dc)
54
+ end
55
+
56
+ # Upcase filenames
57
+ def upcase
58
+ proc_uc = Proc.new do |file|
59
+ new = file.upcase
60
+ rename_fs(file, new)
61
+ end
62
+ run(proc_uc)
63
+ end
64
+
65
+ # Replace spaces in filenames by underscores
66
+ def space_to_underscore
67
+ proc_s2u = Proc.new do |file|
68
+ new = file.gsub(/\s/, '_')
69
+ rename(file, new)
70
+ end
71
+ run(proc_s2u)
72
+ end
73
+
74
+ # Convert underscores to spaces
75
+ def underscore_to_space
76
+ proc_u2s = Proc.new do |file|
77
+ new = file.gsub(/_/, ' ')
78
+ rename(file, new)
79
+ end
80
+ run(proc_u2s)
81
+ end
82
+
83
+ # Capitalize filenames
84
+ def capitalize
85
+ proc_capitalize = Proc.new do |file|
86
+ new = file.capitalize
87
+ rename_fs(file, new)
88
+ end
89
+ run(proc_capitalize)
90
+ end
91
+
92
+ # Capitalize each word
93
+ def capitalize_words
94
+ proc_wcapitalize = Proc.new do |file|
95
+ # We start with a clean downcase name
96
+ new = file.downcase
97
+ # Processing each words
98
+ new.gsub!(/(?:^|[\s_\b\.])\w/) { |el| el.upcase }
99
+ # extension has to be downcase
100
+ new.gsub!(/(\.\w+$)/) { |el| el.downcase }
101
+ # dotfiles have to be downcase
102
+ new.downcase! if new =~ /^\..+/
103
+ rename_fs(file, new)
104
+ end
105
+ run(proc_wcapitalize)
106
+ end
107
+
108
+ # Rename files using a basename and a four digits number
109
+ def basename(bn)
110
+ proc_basename = Proc.new do |file, basename|
111
+ i = "0000"
112
+ file =~ /.*?\.(.*)$/
113
+ if $1 then
114
+ while File.exist?("#{basename}#{i}.#{$1}")
115
+ i = i.to_i + 1
116
+ i = sprintf("%04d", i.to_i)
117
+ end
118
+ new = basename + i + "." + $1
119
+ else
120
+ while File.exist?("#{basename}#{i}")
121
+ i = i.to_i + 1
122
+ i = sprintf("%04d", i.to_i)
123
+ end
124
+ new = basename + i
125
+ end
126
+ rename(file, new)
127
+ end
128
+ run(proc_basename, bn)
129
+ end
130
+
131
+ # Change file extensions
132
+ def ext(e)
133
+ proc_ext = Proc.new do |file, extension|
134
+ # We don't want to process dotfiles
135
+ unless file =~ /^\./ # BUG : Don't work on subdirectories
136
+ # We want to remove the last extension
137
+ name = file.split(".")
138
+ name = name[0...-1].join(".") if name.size > 1
139
+ name = name.to_s
140
+ # Adding the new extension
141
+ new = (extension == "" ? name : name + "." + extension)
142
+ rename(file, new)
143
+ end
144
+ end
145
+ run(proc_ext, e)
146
+ end
147
+
148
+ private
149
+ # Helper to test files and run the specific job
150
+ def run(a_proc, *others)
151
+ @filenames.each do |file|
152
+ if File.exist?(file) then
153
+ if File.writable?(file) then
154
+ # TODO: Improve the processing, we should work on absolute pathnames rather than
155
+ # switching from a directory to another one for each file
156
+ cur_dir = Dir.pwd
157
+ Dir.chdir(File.dirname(file))
158
+ a_proc.call(File.basename(file), *others)
159
+ Dir.chdir(cur_dir)
160
+ else
161
+ warn _("%s: You don't have write access on %s") % [Const::NAME, file]
162
+ end
163
+ else
164
+ warn _("%s: File \"%s\" doesn't exists!") % [Const::NAME, file]
165
+ end
166
+ end
167
+ end
168
+
169
+ # Helper to rename files
170
+ def rename(old, new)
171
+ if not File.exist?(new) then
172
+ File.rename(old, new)
173
+ else
174
+ warn EXISTS
175
+ end
176
+ end
177
+
178
+ # Helper to rename files ensuring compatibily on all FS
179
+ def rename_fs(old, new)
180
+ unless File.exist?(new)
181
+ File.rename(old, "#{old}.tmp")
182
+ File.rename("#{old}.tmp", new)
183
+ else
184
+ warn EXISTS
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,105 @@
1
+ # translation of renamer.po to Français
2
+ # translation of fr.po to Français
3
+ # French translations for Renamer
4
+ # Copyright (C) 2005-2006 Nicolas Cavigneaux <nico@bounga.org>
5
+ # This file is distributed under the same license as Renamer.
6
+ # Nicolas Cavigneaux <nico@bounga.org>, 2005, 2006.
7
+ #
8
+ msgid ""
9
+ msgstr ""
10
+ "Project-Id-Version: renamer\n"
11
+ "POT-Creation-Date: 2006-01-07 21:42+0100\n"
12
+ "PO-Revision-Date: 2006-01-07 21:44+0100\n"
13
+ "Last-Translator: Nicolas Cavigneaux <nico@bounga.org>\n"
14
+ "Language-Team: Français <fr@li.org>\n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=UTF-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+ "Plural-Forms: nplurals=2; plural=(n > 1);\n"
19
+ "X-Generator: KBabel 1.10.2\n"
20
+
21
+ #: bin/renamer:73
22
+ msgid "Specific options:"
23
+ msgstr "Options spécifiques :"
24
+
25
+ #: bin/renamer:75
26
+ msgid "Downcase FILENAMES"
27
+ msgstr "Mettre FICHIERS en minuscules"
28
+
29
+ #: bin/renamer:76
30
+ msgid "Upcase FILENAMES"
31
+ msgstr "Mettre FICHIERS en majuscules"
32
+
33
+ #: bin/renamer:77
34
+ msgid "Capitalize FILENAMES"
35
+ msgstr "Capitalise FICHIERS"
36
+
37
+ #: bin/renamer:78
38
+ msgid "Capitalize each words in FILENAMES"
39
+ msgstr "Capitalise chaque mot dans FICHIERS"
40
+
41
+ #: bin/renamer:79
42
+ #, fuzzy
43
+ msgid "Replace spaces by underscores in FILENAMES"
44
+ msgstr "Capitalise chaque mot dans FICHIERS"
45
+
46
+ #: bin/renamer:80
47
+ msgid "Replace underscores by spaces in FILENAMES"
48
+ msgstr "Remplace les blancs soulignés par des espaces dans FICHIERS "
49
+
50
+ #: bin/renamer:81
51
+ msgid "--basename BASENAME"
52
+ msgstr "--basename NOM_DE_BASE"
53
+
54
+ #: bin/renamer:81
55
+ msgid "Rename FILENAMES using the specified"
56
+ msgstr "Renomme FICHIERS. en utilisant le"
57
+
58
+ #: bin/renamer:81
59
+ msgid "BASENAME followed by an incremental number"
60
+ msgstr "NOM_DE_BASE spécifié suivit d'un nombre incrémental"
61
+
62
+ #: bin/renamer:82
63
+ msgid "--ext NEW"
64
+ msgstr "--ext NOUVELLE"
65
+
66
+ #: bin/renamer:82
67
+ msgid "Rename FILENAMES from their actual extension"
68
+ msgstr "Renomme FICHIERS de leur extension actuelle"
69
+
70
+ #: bin/renamer:82
71
+ msgid "to the NEW one"
72
+ msgstr "à la NOUVELLE"
73
+
74
+ #: bin/renamer:83
75
+ msgid "Run %s recursively across directories"
76
+ msgstr "Éxécute %s récurisivement à travers les répertoires"
77
+
78
+ #: bin/renamer:86
79
+ msgid "Common options:"
80
+ msgstr "Options habituelles"
81
+
82
+ #: bin/renamer:88
83
+ msgid "Show this help"
84
+ msgstr "Affiche cette aide"
85
+
86
+ #: bin/renamer:89
87
+ msgid "Show %s version"
88
+ msgstr "Affiche la version de %s"
89
+
90
+ #: bin/renamer:90
91
+ msgid "Show some information about %s license"
92
+ msgstr "Affiche quelques informations à propos de la licence de %s"
93
+
94
+ #: lib/renamer.rb:24
95
+ msgid "%s: The destination file already exists!"
96
+ msgstr "%s : Le fichier de destination existe déjà !"
97
+
98
+ #: lib/renamer.rb:161
99
+ msgid "%s: You don't have write access on %s"
100
+ msgstr "%s : Vous n'avez pas les droits en écriture sur %s"
101
+
102
+ #: lib/renamer.rb:164
103
+ msgid "%s: File \"%s\" doesn't exists!"
104
+ msgstr "%s : Le fichier \"%s\" n'existe pas !"
105
+
@@ -0,0 +1,101 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: 0.4.0\n"
10
+ "POT-Creation-Date: 2006-01-07 21:43+0100\n"
11
+ "PO-Revision-Date: 2005-12-16 21:30+0100\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "MIME-Version: 1.0\n"
15
+ "Content-Type: text/plain; charset=UTF-8\n"
16
+ "Content-Transfer-Encoding: 8bit\n"
17
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
18
+
19
+ #: bin/renamer:73
20
+ msgid "Specific options:"
21
+ msgstr ""
22
+
23
+ #: bin/renamer:75
24
+ msgid "Downcase FILENAMES"
25
+ msgstr ""
26
+
27
+ #: bin/renamer:76
28
+ msgid "Upcase FILENAMES"
29
+ msgstr ""
30
+
31
+ #: bin/renamer:77
32
+ msgid "Capitalize FILENAMES"
33
+ msgstr ""
34
+
35
+ #: bin/renamer:78
36
+ msgid "Capitalize each words in FILENAMES"
37
+ msgstr ""
38
+
39
+ #: bin/renamer:79
40
+ msgid "Replace spaces by underscores in FILENAMES"
41
+ msgstr ""
42
+
43
+ #: bin/renamer:80
44
+ msgid "Replace underscores by spaces in FILENAMES"
45
+ msgstr ""
46
+
47
+ #: bin/renamer:81
48
+ msgid "--basename BASENAME"
49
+ msgstr ""
50
+
51
+ #: bin/renamer:81
52
+ msgid "Rename FILENAMES using the specified"
53
+ msgstr ""
54
+
55
+ #: bin/renamer:81
56
+ msgid "BASENAME followed by an incremental number"
57
+ msgstr ""
58
+
59
+ #: bin/renamer:82
60
+ msgid "--ext NEW"
61
+ msgstr ""
62
+
63
+ #: bin/renamer:82
64
+ msgid "Rename FILENAMES from their actual extension"
65
+ msgstr ""
66
+
67
+ #: bin/renamer:82
68
+ msgid "to the NEW one"
69
+ msgstr ""
70
+
71
+ #: bin/renamer:83
72
+ msgid "Run %s recursively across directories"
73
+ msgstr ""
74
+
75
+ #: bin/renamer:86
76
+ msgid "Common options:"
77
+ msgstr ""
78
+
79
+ #: bin/renamer:88
80
+ msgid "Show this help"
81
+ msgstr ""
82
+
83
+ #: bin/renamer:89
84
+ msgid "Show %s version"
85
+ msgstr ""
86
+
87
+ #: bin/renamer:90
88
+ msgid "Show some information about %s license"
89
+ msgstr ""
90
+
91
+ #: lib/renamer.rb:24
92
+ msgid "%s: The destination file already exists!"
93
+ msgstr ""
94
+
95
+ #: lib/renamer.rb:161
96
+ msgid "%s: You don't have write access on %s"
97
+ msgstr ""
98
+
99
+ #: lib/renamer.rb:164
100
+ msgid "%s: File \"%s\" doesn't exists!"
101
+ msgstr ""
@@ -0,0 +1,256 @@
1
+ #!/usr/bin/ruby -w
2
+ =begin
3
+ Copyright (c) 2004-2006 by Nicolas Cavigneaux <nico@bounga.org>
4
+ See COPYING for License detail.
5
+
6
+ This program is free software; you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation; either version 2 of the License, or
9
+ (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with this program; if not, write to the Free Software
18
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ =end
20
+
21
+ # Loading needed libs
22
+ begin
23
+ require 'rubygems'
24
+ rescue LoadError
25
+ warn "Not using RubyGems" if $DEBUG
26
+ end
27
+
28
+ $:.unshift(File.dirname(__FILE__) + "/../lib/")
29
+
30
+ require 'test/unit'
31
+ require 'rubygems'
32
+ require 'gettext'
33
+ require 'fileutils'
34
+ require 'const'
35
+ require 'renamer'
36
+
37
+ # Testing
38
+ class TestRenamer < Test::Unit::TestCase
39
+ def setup
40
+ $VERBOSE = nil
41
+ @files = Array.new
42
+ Dir.mkdir("tmp_files")
43
+ Dir.chdir("tmp_files")
44
+ end
45
+
46
+ def teardown
47
+ Dir.chdir("..")
48
+ FileUtils.rm_rf("tmp_files")
49
+ end
50
+
51
+ def test_mv
52
+ @files << File.new("PLOP", "w").path
53
+ @files << File.new("TesT.Hop", "w").path
54
+
55
+ r = Renamer.new(@files)
56
+ r.downcase
57
+
58
+ assert_raise(Errno::ENOENT) { File.open("PLOP.txt") }
59
+ assert_raise(Errno::ENOENT) { File.open("TesT.Hop") }
60
+ end
61
+
62
+ def test_subdirectory
63
+ Dir.mkdir("test1")
64
+ Dir.mkdir("test2")
65
+ @files << File.new("test1/PLOP.txt", "w").path
66
+ @files << File.new("test2/PLOP.txt", "w").path
67
+
68
+ r = Renamer.new(@files)
69
+ r.downcase
70
+
71
+ assert_nothing_raised(Errno::ENOENT) { File.open("test1/plop.txt") }
72
+ assert_nothing_raised(Errno::ENOENT) { File.open("test2/plop.txt") }
73
+ end
74
+
75
+ def test_recursivity
76
+ Dir.mkdir("test1")
77
+ Dir.mkdir("test1/test3")
78
+ Dir.mkdir("test1/test3/test4")
79
+ Dir.mkdir("test2")
80
+ @files << File.new("test1/PLOP.txt", "w").path
81
+ @files << File.new("test1/test3/PLOP.txt", "w").path
82
+ @files << File.new("test1/test3/test4/PLOP.txt", "w").path
83
+ @files << File.new("test2/PLOP.txt", "w").path
84
+
85
+ r = Renamer.new(@files, true)
86
+ r.downcase
87
+
88
+ assert_nothing_raised(Errno::ENOENT) { File.open("test1/plop.txt") }
89
+ assert_nothing_raised(Errno::ENOENT) { File.open("test1/test3/plop.txt") }
90
+ assert_nothing_raised(Errno::ENOENT) { File.open("test1/test3/test4/plop.txt") }
91
+ assert_nothing_raised(Errno::ENOENT) { File.open("test2/plop.txt") }
92
+ end
93
+
94
+ def test_downcase
95
+ @files << File.new("PLOP", "w").path
96
+ @files << File.new("PLOP.txt", "w").path
97
+ @files << File.new("PLOP.JPG", "w").path
98
+ @files << File.new("TesT.Hop", "w").path
99
+ @files << File.new("test.txt", "w").path
100
+ @files << File.new("teST.jpg.txt", "w").path
101
+
102
+ r = Renamer.new(@files)
103
+ r.downcase
104
+
105
+ assert_nothing_raised(Errno::ENOENT) { File.open("plop") }
106
+ assert_nothing_raised(Errno::ENOENT) { File.open("plop.txt") }
107
+ assert_nothing_raised(Errno::ENOENT) { File.open("plop.jpg") }
108
+ assert_nothing_raised(Errno::ENOENT) { File.open("test.hop") }
109
+ assert_nothing_raised(Errno::ENOENT) { File.open("test.txt") }
110
+ assert_nothing_raised(Errno::ENOENT) { File.open("test.jpg.txt") }
111
+ end
112
+
113
+ def test_upcase
114
+ @files << File.new("plop", "w").path
115
+ @files << File.new("PLOP.txt", "w").path
116
+ @files << File.new("PLOP.JPG", "w").path
117
+ @files << File.new("TesT.Hop", "w").path
118
+ @files << File.new("test.txt", "w").path
119
+ @files << File.new("teST.jpg.txt", "w").path
120
+
121
+ r = Renamer.new(@files)
122
+ r.upcase
123
+
124
+ assert_nothing_raised(Errno::ENOENT) { File.open("PLOP") }
125
+ assert_nothing_raised(Errno::ENOENT) { File.open("PLOP.TXT") }
126
+ assert_nothing_raised(Errno::ENOENT) { File.open("PLOP.JPG") }
127
+ assert_nothing_raised(Errno::ENOENT) { File.open("TEST.HOP") }
128
+ assert_nothing_raised(Errno::ENOENT) { File.open("TEST.TXT") }
129
+ assert_nothing_raised(Errno::ENOENT) { File.open("TEST.JPG.TXT") }
130
+ end
131
+
132
+ def test_space_to_underscore
133
+ @files << File.new("plop plop", "w").path
134
+ @files << File.new("PLOP.txt", "w").path
135
+ @files << File.new("PLOP PLOP PLOP.avi", "w").path
136
+ @files << File.new("TesT .Hop", "w").path
137
+ @files << File.new("test. txt", "w").path
138
+ @files << File.new("teST.jpg.txt", "w").path
139
+
140
+ r = Renamer.new(@files)
141
+ r.space_to_underscore
142
+
143
+ assert_nothing_raised(Errno::ENOENT) { File.open("plop_plop") }
144
+ assert_nothing_raised(Errno::ENOENT) { File.open("PLOP.txt") }
145
+ assert_nothing_raised(Errno::ENOENT) { File.open("PLOP_PLOP_PLOP.avi") }
146
+ assert_nothing_raised(Errno::ENOENT) { File.open("TesT_.Hop") }
147
+ assert_nothing_raised(Errno::ENOENT) { File.open("test._txt") }
148
+ assert_nothing_raised(Errno::ENOENT) { File.open("teST.jpg.txt") }
149
+ end
150
+
151
+ def test_underscore_to_space
152
+ @files << File.new("plop_plop", "w").path
153
+ @files << File.new("PLOP.txt", "w").path
154
+ @files << File.new("PLOP_PLOP_PLOP.avi", "w").path
155
+ @files << File.new("TesT_.Hop", "w").path
156
+ @files << File.new("test._txt", "w").path
157
+ @files << File.new("teST.jpg.txt", "w").path
158
+
159
+ r = Renamer.new(@files)
160
+ r.underscore_to_space
161
+
162
+ assert_nothing_raised(Errno::ENOENT) { File.open("plop plop") }
163
+ assert_nothing_raised(Errno::ENOENT) { File.open("PLOP.txt") }
164
+ assert_nothing_raised(Errno::ENOENT) { File.open("PLOP PLOP PLOP.avi") }
165
+ assert_nothing_raised(Errno::ENOENT) { File.open("TesT .Hop") }
166
+ assert_nothing_raised(Errno::ENOENT) { File.open("test. txt") }
167
+ assert_nothing_raised(Errno::ENOENT) { File.open("teST.jpg.txt") }
168
+ end
169
+
170
+ def test_capitalize
171
+ @files << File.new("plop_plop", "w").path
172
+ @files << File.new("PLOP.txt", "w").path
173
+ @files << File.new("Plop.avi", "w").path
174
+ @files << File.new("TesT_.Hop", "w").path
175
+ @files << File.new("test test.TXT", "w").path
176
+ @files << File.new("teST.jpg.txt", "w").path
177
+
178
+ r = Renamer.new(@files)
179
+ r.capitalize
180
+
181
+ assert_nothing_raised(Errno::ENOENT) { File.open("Plop_plop") }
182
+ assert_nothing_raised(Errno::ENOENT) { File.open("Plop.txt") }
183
+ assert_nothing_raised(Errno::ENOENT) { File.open("Plop.avi") }
184
+ assert_nothing_raised(Errno::ENOENT) { File.open("Test_.hop") }
185
+ assert_nothing_raised(Errno::ENOENT) { File.open("Test test.txt") }
186
+ assert_nothing_raised(Errno::ENOENT) { File.open("Test.jpg.txt") }
187
+ end
188
+
189
+ def test_capitalize_words
190
+ @files << File.new("plop_plop", "w").path
191
+ @files << File.new("PLOP.txt", "w").path
192
+ @files << File.new("Plop.avi", "w").path
193
+ @files << File.new("TesT_.Hop", "w").path
194
+ @files << File.new("test test.txt", "w").path
195
+ @files << File.new("test test_test.txt", "w").path
196
+ @files << File.new("teST.jpg.txt", "w").path
197
+ @files << File.new(".dotfile", "w").path
198
+
199
+ r = Renamer.new(@files)
200
+ r.capitalize_words
201
+
202
+ assert_nothing_raised(Errno::ENOENT) { File.open("Plop_Plop") }
203
+ assert_nothing_raised(Errno::ENOENT) { File.open("Plop.txt") }
204
+ assert_nothing_raised(Errno::ENOENT) { File.open("Plop.avi") }
205
+ assert_nothing_raised(Errno::ENOENT) { File.open("Test_.hop") }
206
+ assert_nothing_raised(Errno::ENOENT) { File.open("Test Test.txt") }
207
+ assert_nothing_raised(Errno::ENOENT) { File.open("Test Test_Test.txt") }
208
+ assert_nothing_raised(Errno::ENOENT) { File.open("Test.Jpg.txt") }
209
+ assert_nothing_raised(Errno::ENOENT) { File.open(".dotfile") }
210
+ end
211
+
212
+ def test_basename
213
+ @files << File.new("plop_plop.txt", "w").path
214
+ @files << File.new("PLOP.txt", "w").path
215
+ @files << File.new("TesT_.txt", "w").path
216
+ @files << File.new("test test.txt", "w").path
217
+ @files << File.new("test test_test.txt", "w").path
218
+ @files << File.new("teST.jpg.txt", "w").path
219
+ @files << File.new("Plop", "w").path
220
+ @files << File.new("test0004.txt", "w").path
221
+
222
+ r = Renamer.new(@files)
223
+ r.basename("test")
224
+
225
+ assert_nothing_raised(Errno::ENOENT) { File.open("test0000.txt") }
226
+ assert_nothing_raised(Errno::ENOENT) { File.open("test0001.txt") }
227
+ assert_nothing_raised(Errno::ENOENT) { File.open("test0002.txt") }
228
+ assert_nothing_raised(Errno::ENOENT) { File.open("test0003.txt") }
229
+ assert_nothing_raised(Errno::ENOENT) { File.open("test0005.txt") }
230
+ assert_nothing_raised(Errno::ENOENT) { File.open("test0006.txt") }
231
+ assert_nothing_raised(Errno::ENOENT) { File.open("test0000") }
232
+ end
233
+
234
+ def test_ext
235
+ @files << File.new("plop_plop", "w").path
236
+ @files << File.new("PLOP.txt", "w").path
237
+ @files << File.new("Plop.avi", "w").path
238
+ @files << File.new("TesT_.Hop", "w").path
239
+ @files << File.new("test test.txt", "w").path
240
+ @files << File.new("test test_test.txt", "w").path
241
+ @files << File.new("teST.jpg.txt", "w").path
242
+ @files << File.new(".dotfile", "w").path
243
+
244
+ r = Renamer.new(@files)
245
+ r.ext("rnm")
246
+
247
+ assert_nothing_raised(Errno::ENOENT) { File.open("plop_plop.rnm") }
248
+ assert_nothing_raised(Errno::ENOENT) { File.open("PLOP.rnm") }
249
+ assert_nothing_raised(Errno::ENOENT) { File.open("Plop.rnm") }
250
+ assert_nothing_raised(Errno::ENOENT) { File.open("TesT_.rnm") }
251
+ assert_nothing_raised(Errno::ENOENT) { File.open("test test.rnm") }
252
+ assert_nothing_raised(Errno::ENOENT) { File.open("test test_test.rnm") }
253
+ assert_nothing_raised(Errno::ENOENT) { File.open("teST.jpg.rnm") }
254
+ assert_nothing_raised(Errno::ENOENT) { File.open(".dotfile") }
255
+ end
256
+ end