deblank 0.1.0 → 0.2.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.
- checksums.yaml +5 -5
- data/Gemfile +6 -0
- data/README.md +2 -2
- data/Rakefile +22 -26
- data/bin/deblank +2 -1
- data/deblank.gemspec +21 -19
- data/lib/deblank.rb +52 -52
- data/man/deblank.1 +4 -4
- data/test/test_nameconverter.rb +19 -24
- data/test/test_optionparser.rb +20 -25
- metadata +11 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 64eb6816ecca78f248def7e3d9defa6627616337b86a9b67ffb6cd12ade098ab
|
4
|
+
data.tar.gz: 5ae0b56dcf338b04bbc34eb36f678008db547ae57d75f343dd28c24fa9c205f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06ab50f7edbaa7f9b121913382aa3f9a4a7b4ef4f21ccae9fee7e0d9d4b8e28f8fe0de5e45b820054a7f4b937d73033084936e4b17b34e3f0cb29ac054383565
|
7
|
+
data.tar.gz: e10c7f3ab901c07daf07b70253136da314417fa6651350e618bc122ced915ab36e747c43c32fe7688f96c841481b5f16eaf739172e17c31639bf389a2bf3cf24
|
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -51,7 +51,7 @@ Requirements
|
|
51
51
|
|
52
52
|
- No additional Ruby gems are needed to run `deblank`.
|
53
53
|
|
54
|
-
- `deblank` has been tested with Ruby 1
|
54
|
+
- `deblank` has been tested with Ruby 3.1 or higher
|
55
55
|
on Linux and on Windows (command prompt with code page 850).
|
56
56
|
|
57
57
|
Documentation
|
@@ -77,7 +77,7 @@ Report bugs on the `deblank` home page: <https://github.com/stomar/deblank/>
|
|
77
77
|
License
|
78
78
|
-------
|
79
79
|
|
80
|
-
Copyright © 2012-
|
80
|
+
Copyright © 2012-2024 Marcus Stollsteimer
|
81
81
|
|
82
82
|
`deblank` is free software: you can redistribute it and/or modify
|
83
83
|
it under the terms of the GNU General Public License version 3 or later (GPLv3+),
|
data/Rakefile
CHANGED
@@ -1,52 +1,49 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Copyright (C) 2012-2013 Marcus Stollsteimer
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
require
|
3
|
+
require "rake/testtask"
|
6
4
|
|
7
|
-
require
|
5
|
+
require "./lib/deblank"
|
8
6
|
|
9
7
|
PROGNAME = Deblank::PROGNAME
|
10
8
|
HOMEPAGE = Deblank::HOMEPAGE
|
11
9
|
TAGLINE = Deblank::TAGLINE
|
12
10
|
|
13
|
-
BINDIR =
|
14
|
-
MANDIR =
|
11
|
+
BINDIR = "/usr/local/bin"
|
12
|
+
MANDIR = "/usr/local/man/man1"
|
15
13
|
|
16
|
-
HELP2MAN =
|
17
|
-
SED =
|
14
|
+
HELP2MAN = "help2man"
|
15
|
+
SED = "sed"
|
18
16
|
|
19
|
-
BINARY =
|
20
|
-
BINARYNAME =
|
21
|
-
MANPAGE =
|
22
|
-
H2MFILE =
|
17
|
+
BINARY = "lib/deblank.rb"
|
18
|
+
BINARYNAME = "deblank" # install using this name
|
19
|
+
MANPAGE = "man/deblank.1"
|
20
|
+
H2MFILE = "deblank.h2m"
|
23
21
|
|
24
22
|
|
25
23
|
def gemspec_file
|
26
|
-
|
24
|
+
"deblank.gemspec"
|
27
25
|
end
|
28
26
|
|
29
27
|
|
30
|
-
task :
|
28
|
+
task default: [:test]
|
31
29
|
|
32
30
|
Rake::TestTask.new do |t|
|
33
|
-
t.pattern =
|
34
|
-
t.ruby_opts << '-rubygems'
|
31
|
+
t.pattern = "test/**/test_*.rb"
|
35
32
|
t.verbose = true
|
36
33
|
t.warning = true
|
37
34
|
end
|
38
35
|
|
39
36
|
|
40
|
-
desc
|
41
|
-
task :
|
37
|
+
desc "Install binary and man page"
|
38
|
+
task install: [BINARY, MANPAGE] do
|
42
39
|
mkdir_p BINDIR
|
43
40
|
install(BINARY, "#{BINDIR}/#{BINARYNAME}")
|
44
41
|
mkdir_p MANDIR
|
45
|
-
install(MANPAGE, MANDIR, :
|
42
|
+
install(MANPAGE, MANDIR, mode: 0o644)
|
46
43
|
end
|
47
44
|
|
48
45
|
|
49
|
-
desc
|
46
|
+
desc "Uninstall binary and man page"
|
50
47
|
task :uninstall do
|
51
48
|
rm "#{BINDIR}/#{BINARYNAME}"
|
52
49
|
manfile = File.basename(MANPAGE)
|
@@ -54,19 +51,18 @@ task :uninstall do
|
|
54
51
|
end
|
55
52
|
|
56
53
|
|
57
|
-
desc
|
58
|
-
task :
|
54
|
+
desc "Create man page"
|
55
|
+
task man: [MANPAGE]
|
59
56
|
|
60
57
|
file MANPAGE => [BINARY, H2MFILE] do
|
61
58
|
sh "#{HELP2MAN} --no-info --name='#{TAGLINE}' --include=#{H2MFILE} -o #{MANPAGE} ./#{BINARY}"
|
62
|
-
sh "#{SED} -i '/\.PP/{N;s/\.PP\\nOptions/.SH OPTIONS/}' #{MANPAGE}"
|
63
59
|
sh "#{SED} -i 's/^License GPL/.br\\nLicense GPL/;s/There is NO WARRANTY/.br\\nThere is NO WARRANTY/' #{MANPAGE}"
|
64
60
|
sh "#{SED} -i 's!%HOMEPAGE%!#{HOMEPAGE}!g' #{MANPAGE}"
|
65
61
|
sh "#{SED} -i 's!%PROGNAME%!#{PROGNAME}!g' #{MANPAGE}"
|
66
62
|
end
|
67
63
|
|
68
64
|
|
69
|
-
desc
|
70
|
-
task :
|
65
|
+
desc "Build gem"
|
66
|
+
task build: [MANPAGE] do
|
71
67
|
sh "gem build #{gemspec_file}"
|
72
68
|
end
|
data/bin/deblank
CHANGED
data/deblank.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "./lib/deblank"
|
2
4
|
|
3
5
|
version = Deblank::VERSION
|
4
6
|
date = Deblank::DATE
|
@@ -6,39 +8,39 @@ homepage = Deblank::HOMEPAGE
|
|
6
8
|
tagline = Deblank::TAGLINE
|
7
9
|
|
8
10
|
Gem::Specification.new do |s|
|
9
|
-
s.name =
|
11
|
+
s.name = "deblank"
|
10
12
|
s.version = version
|
11
13
|
s.date = date
|
12
14
|
|
13
|
-
s.description =
|
14
|
-
|
15
|
-
|
15
|
+
s.description = "deblank is a command line tool that " \
|
16
|
+
"renames files and replaces or removes special characters " \
|
17
|
+
"like spaces, parentheses, or umlauts."
|
16
18
|
s.summary = "deblank - #{tagline}"
|
17
19
|
|
18
|
-
s.authors = [
|
19
|
-
s.email =
|
20
|
+
s.authors = ["Marcus Stollsteimer"]
|
21
|
+
s.email = "sto.mar@web.de"
|
20
22
|
s.homepage = homepage
|
21
23
|
|
22
|
-
s.license =
|
23
|
-
|
24
|
-
s.required_ruby_version = '>=1.9.2'
|
24
|
+
s.license = "GPL-3.0"
|
25
25
|
|
26
|
-
s.
|
26
|
+
s.required_ruby_version = ">= 3.1.0"
|
27
27
|
|
28
|
-
s.executables = [
|
29
|
-
s.bindir =
|
28
|
+
s.executables = ["deblank"]
|
29
|
+
s.bindir = "bin"
|
30
30
|
|
31
|
-
s.
|
31
|
+
s.require_paths = ["lib"]
|
32
32
|
|
33
|
-
s.test_files = Dir.glob(
|
33
|
+
s.test_files = Dir.glob("test/**/test_*.rb")
|
34
34
|
|
35
|
-
s.files =
|
35
|
+
s.files =
|
36
|
+
%w[
|
36
37
|
README.md
|
37
38
|
Rakefile
|
39
|
+
Gemfile
|
38
40
|
deblank.gemspec
|
39
41
|
deblank.h2m
|
40
|
-
|
41
|
-
Dir.glob(
|
42
|
+
] +
|
43
|
+
Dir.glob("{bin,lib,man,test}/**/*")
|
42
44
|
|
43
|
-
s.rdoc_options = [
|
45
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
44
46
|
end
|
data/lib/deblank.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
3
4
|
# == Name
|
4
5
|
#
|
5
6
|
# deblank - remove special characters from filenames
|
@@ -15,27 +16,27 @@
|
|
15
16
|
#
|
16
17
|
# == Author
|
17
18
|
#
|
18
|
-
# Copyright (C) 2012-
|
19
|
+
# Copyright (C) 2012-2024 Marcus Stollsteimer
|
19
20
|
#
|
20
21
|
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
|
21
22
|
|
22
|
-
require
|
23
|
+
require "optparse"
|
23
24
|
|
24
25
|
# This module contains the classes for the +deblank+ tool.
|
25
26
|
module Deblank
|
26
27
|
|
27
|
-
PROGNAME =
|
28
|
-
VERSION =
|
29
|
-
DATE =
|
30
|
-
HOMEPAGE =
|
31
|
-
TAGLINE =
|
28
|
+
PROGNAME = "deblank"
|
29
|
+
VERSION = "0.2.0"
|
30
|
+
DATE = "2024-01-05"
|
31
|
+
HOMEPAGE = "https://github.com/stomar/deblank"
|
32
|
+
TAGLINE = "remove special characters from filenames"
|
32
33
|
|
33
|
-
COPYRIGHT =
|
34
|
-
Copyright (C) 2012-
|
34
|
+
COPYRIGHT = <<~TEXT
|
35
|
+
Copyright (C) 2012-2024 Marcus Stollsteimer.
|
35
36
|
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
36
37
|
This is free software: you are free to change and redistribute it.
|
37
38
|
There is NO WARRANTY, to the extent permitted by law.
|
38
|
-
|
39
|
+
TEXT
|
39
40
|
|
40
41
|
# Parser for the command line options.
|
41
42
|
# The class method parse! does the job.
|
@@ -49,62 +50,62 @@ module Deblank
|
|
49
50
|
#
|
50
51
|
# Returns a hash containing the option parameters.
|
51
52
|
def self.parse!(argv)
|
52
|
-
|
53
53
|
options = {
|
54
|
-
:
|
55
|
-
:
|
54
|
+
files: nil,
|
55
|
+
simulate: false
|
56
56
|
}
|
57
57
|
|
58
58
|
opt_parser = OptionParser.new do |opt|
|
59
59
|
opt.banner = "Usage: #{PROGNAME} [options] file[s]"
|
60
|
-
opt.separator
|
60
|
+
opt.separator ""
|
61
|
+
opt.separator <<~DESCRIPTION
|
61
62
|
deblank renames files and replaces or removes special characters
|
62
63
|
like spaces, parentheses, or umlauts.
|
63
64
|
The new filename will only contain the following characters:
|
64
65
|
|
65
|
-
|
66
|
+
#{NameConverter.default_valid_chars_to_s}
|
66
67
|
|
67
68
|
Spaces are replaced by underscores, German umlauts and eszett are
|
68
69
|
transliterated, all other invalid characters are removed.
|
69
70
|
|
70
|
-
Options
|
71
|
-
|
71
|
+
Options:
|
72
|
+
DESCRIPTION
|
72
73
|
|
73
74
|
# process --version and --help first,
|
74
75
|
# exit successfully (GNU Coding Standards)
|
75
|
-
opt.on_tail(
|
76
|
+
opt.on_tail("-h", "--help", "Print a brief help message and exit.") do
|
76
77
|
puts opt_parser
|
77
78
|
puts "\nReport bugs on the #{PROGNAME} home page: <#{HOMEPAGE}>"
|
78
79
|
exit
|
79
80
|
end
|
80
81
|
|
81
|
-
opt.on_tail(
|
82
|
-
|
82
|
+
opt.on_tail("-v", "--version",
|
83
|
+
"Print a brief version information and exit.") do
|
83
84
|
puts "#{PROGNAME} #{VERSION}"
|
84
85
|
puts COPYRIGHT
|
85
86
|
exit
|
86
87
|
end
|
87
88
|
|
88
|
-
opt.on(
|
89
|
-
|
89
|
+
opt.on("-l", "--list",
|
90
|
+
"List the used character substitutions.") do
|
90
91
|
puts NameConverter.default_substitutions_to_s
|
91
92
|
exit
|
92
93
|
end
|
93
94
|
|
94
|
-
opt.on(
|
95
|
-
|
95
|
+
opt.on("-n", "--no-act",
|
96
|
+
"Do not rename files, only display what would happen.") do
|
96
97
|
options[:simulate] = true
|
97
98
|
end
|
98
99
|
|
99
|
-
opt.separator
|
100
|
+
opt.separator ""
|
100
101
|
end
|
101
102
|
opt_parser.parse!(argv)
|
102
103
|
|
103
104
|
# only file[s] should be left (at least 1 argument)
|
104
|
-
raise(ArgumentError,
|
105
|
+
raise(ArgumentError, "wrong number of arguments") if argv.empty?
|
105
106
|
|
106
107
|
options[:files] = Array.new(argv).map do |filename|
|
107
|
-
correct_encoding(filename).encode(
|
108
|
+
correct_encoding(filename).encode("UTF-8")
|
108
109
|
end
|
109
110
|
argv.clear
|
110
111
|
|
@@ -122,7 +123,7 @@ module Deblank
|
|
122
123
|
def self.correct_encoding(string)
|
123
124
|
return string unless string.encoding == Encoding::CP850
|
124
125
|
|
125
|
-
string.dup.force_encoding(
|
126
|
+
string.dup.force_encoding("Windows-1252")
|
126
127
|
end
|
127
128
|
end
|
128
129
|
|
@@ -130,18 +131,18 @@ module Deblank
|
|
130
131
|
# (only the base name is modified).
|
131
132
|
class NameConverter
|
132
133
|
|
133
|
-
VALID_CHARS =
|
134
|
+
VALID_CHARS = "A-Za-z0-9._-" # `-' must be last
|
134
135
|
|
135
136
|
SUBSTITUTIONS = {
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
}
|
137
|
+
" " => "_",
|
138
|
+
"ä" => "ae",
|
139
|
+
"ö" => "oe",
|
140
|
+
"ü" => "ue",
|
141
|
+
"Ä" => "Ae",
|
142
|
+
"Ö" => "Oe",
|
143
|
+
"Ü" => "Ue",
|
144
|
+
"ß" => "ss"
|
145
|
+
}.freeze
|
145
146
|
|
146
147
|
def initialize
|
147
148
|
@valid_characters = VALID_CHARS
|
@@ -152,17 +153,17 @@ module Deblank
|
|
152
153
|
dir, basename = File.dirname(filename), File.basename(filename)
|
153
154
|
|
154
155
|
@substitutions.each {|from, to| basename.gsub!(/#{from}/, to) }
|
155
|
-
basename.gsub!(invalid_characters,
|
156
|
+
basename.gsub!(invalid_characters, "")
|
156
157
|
|
157
|
-
dir ==
|
158
|
+
dir == "." ? basename : "#{dir}/#{basename}"
|
158
159
|
end
|
159
160
|
|
160
161
|
def invalid?(filename)
|
161
|
-
invalid_characters
|
162
|
+
filename.match?(invalid_characters)
|
162
163
|
end
|
163
164
|
|
164
165
|
def self.default_valid_chars_to_s
|
165
|
-
VALID_CHARS.scan(/.-.|./).join(
|
166
|
+
VALID_CHARS.scan(/.-.|./).join(" ")
|
166
167
|
end
|
167
168
|
|
168
169
|
def self.default_substitutions_to_s
|
@@ -181,12 +182,12 @@ module Deblank
|
|
181
182
|
# It parses the command line arguments and renames the files.
|
182
183
|
class Application
|
183
184
|
|
184
|
-
ERRORCODE = {:
|
185
|
+
ERRORCODE = { general: 1, usage: 2 }.freeze
|
185
186
|
|
186
187
|
def initialize
|
187
188
|
begin
|
188
189
|
options = Optionparser.parse!(ARGV)
|
189
|
-
rescue => e
|
190
|
+
rescue StandardError => e
|
190
191
|
usage_fail(e.message)
|
191
192
|
end
|
192
193
|
@files = options[:files]
|
@@ -217,13 +218,13 @@ module Deblank
|
|
217
218
|
def file_exist?(filename)
|
218
219
|
fail_message = "There is no file `#{filename}'."
|
219
220
|
|
220
|
-
File.exist?(filename)
|
221
|
+
File.exist?(filename) or skip_warn(fail_message)
|
221
222
|
end
|
222
223
|
|
223
224
|
def invalid?(filename)
|
224
225
|
fail_message = "`#{filename}' already is a valid filename."
|
225
226
|
|
226
|
-
@converter.invalid?(filename)
|
227
|
+
@converter.invalid?(filename) or skip_warn(fail_message)
|
227
228
|
end
|
228
229
|
|
229
230
|
def secure_rename(old_filename, new_filename)
|
@@ -246,7 +247,8 @@ module Deblank
|
|
246
247
|
loop do
|
247
248
|
$stderr.print "#{question} [y/n] "
|
248
249
|
reply = $stdin.gets.chomp.downcase # $stdin avoids gets/ARGV problem
|
249
|
-
return reply ==
|
250
|
+
return reply == "y" if reply.match?(/\A[yn]\z/)
|
251
|
+
|
250
252
|
warn "Please answer `y' or `n'."
|
251
253
|
end
|
252
254
|
end
|
@@ -258,10 +260,8 @@ module Deblank
|
|
258
260
|
exit ERRORCODE[:usage]
|
259
261
|
end
|
260
262
|
end
|
261
|
-
end
|
263
|
+
end
|
262
264
|
|
263
265
|
### call main method only if called on command line
|
264
266
|
|
265
|
-
if __FILE__ == $
|
266
|
-
Deblank::Application.new.run!
|
267
|
-
end
|
267
|
+
Deblank::Application.new.run! if __FILE__ == $PROGRAM_NAME
|
data/man/deblank.1
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.
|
2
|
-
.TH DEBLANK "1" "
|
1
|
+
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.1.
|
2
|
+
.TH DEBLANK "1" "January 2024" "deblank 0.2.0" "User Commands"
|
3
3
|
.SH NAME
|
4
4
|
deblank \- remove special characters from filenames
|
5
5
|
.SH SYNOPSIS
|
6
6
|
.B deblank
|
7
|
-
[\
|
7
|
+
[\fI\,options\/\fR] \fI\,file\/\fR[\fI\,s\/\fR]
|
8
8
|
.SH DESCRIPTION
|
9
9
|
deblank renames files and replaces or removes special characters
|
10
10
|
like spaces, parentheses, or umlauts.
|
@@ -30,7 +30,7 @@ Print a brief version information and exit.
|
|
30
30
|
.SH "REPORTING BUGS"
|
31
31
|
Report bugs on the deblank home page: <https://github.com/stomar/deblank>
|
32
32
|
.SH COPYRIGHT
|
33
|
-
Copyright \(co 2012\-
|
33
|
+
Copyright \(co 2012\-2024 Marcus Stollsteimer.
|
34
34
|
.br
|
35
35
|
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
36
36
|
.br
|
data/test/test_nameconverter.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# test_nameconverter.rb: Unit tests for the deblank script.
|
4
|
-
#
|
5
|
-
# Copyright (C) 2012-2013 Marcus Stollsteimer
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require 'deblank'
|
3
|
+
require "minitest/autorun"
|
4
|
+
require "deblank"
|
10
5
|
|
11
6
|
|
12
7
|
describe Deblank::NameConverter do
|
@@ -15,33 +10,33 @@ describe Deblank::NameConverter do
|
|
15
10
|
@nc = Deblank::NameConverter.new
|
16
11
|
end
|
17
12
|
|
18
|
-
it
|
19
|
-
@nc.invalid?(
|
20
|
-
@nc.invalid?(
|
21
|
-
@nc.invalid?(
|
13
|
+
it "recognizes invalid filenames" do
|
14
|
+
_(@nc.invalid?("path/to/filename with spaces.txt")).must_equal true
|
15
|
+
_(@nc.invalid?("filename_with_ä.txt")).must_equal true
|
16
|
+
_(@nc.invalid?("Valid_filename-1.txt")).must_equal false
|
22
17
|
end
|
23
18
|
|
24
|
-
it
|
25
|
-
@nc.convert(
|
19
|
+
it "does not change the path name" do
|
20
|
+
_(@nc.convert("path with spaces/file.txt")).must_equal "path with spaces/file.txt"
|
26
21
|
end
|
27
22
|
|
28
|
-
it
|
29
|
-
@nc.convert(
|
23
|
+
it "replaces spaces by underscores" do
|
24
|
+
_(@nc.convert("file with spaces.txt")).must_equal "file_with_spaces.txt"
|
30
25
|
end
|
31
26
|
|
32
|
-
it
|
33
|
-
@nc.convert(
|
27
|
+
it "removes parentheses" do
|
28
|
+
_(@nc.convert("file_(another).txt")).must_equal "file_another.txt"
|
34
29
|
end
|
35
30
|
|
36
|
-
it
|
37
|
-
@nc.convert(
|
31
|
+
it "transliterates umlauts and eszett" do
|
32
|
+
_(@nc.convert("Ä_Ö_Ü_ä_ö_ü_ß.txt")).must_equal "Ae_Oe_Ue_ae_oe_ue_ss.txt"
|
38
33
|
end
|
39
34
|
|
40
|
-
it
|
41
|
-
Deblank::NameConverter.default_valid_chars_to_s.must_equal
|
35
|
+
it "can return the default valid characters as string" do
|
36
|
+
_(Deblank::NameConverter.default_valid_chars_to_s).must_equal "A-Z a-z 0-9 . _ -"
|
42
37
|
end
|
43
38
|
|
44
|
-
it
|
45
|
-
Deblank::NameConverter.default_substitutions_to_s.split("\n")[0].must_equal
|
39
|
+
it "can return the default substitutions as string" do
|
40
|
+
_(Deblank::NameConverter.default_substitutions_to_s.split("\n")[0]).must_equal " => _"
|
46
41
|
end
|
47
42
|
end
|
data/test/test_optionparser.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# test_optionparser.rb: Unit tests for the deblank script.
|
4
|
-
#
|
5
|
-
# Copyright (C) 2012-2013 Marcus Stollsteimer
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require 'deblank'
|
3
|
+
require "minitest/autorun"
|
4
|
+
require "deblank"
|
10
5
|
|
11
6
|
|
12
7
|
describe Deblank::Optionparser do
|
@@ -14,35 +9,35 @@ describe Deblank::Optionparser do
|
|
14
9
|
before do
|
15
10
|
@parser = Deblank::Optionparser
|
16
11
|
@arg = "test_ä.txt"
|
17
|
-
@
|
18
|
-
@
|
12
|
+
@arg_win1252_labeled_as_cp850 = (+"test_\xE4.txt").force_encoding("CP850")
|
13
|
+
@arg_win1252 = (+"test_\xE4.txt").force_encoding("Windows-1252")
|
19
14
|
end
|
20
15
|
|
21
|
-
it
|
22
|
-
arg = @
|
23
|
-
arg.encoding.must_equal Encoding::CP850
|
16
|
+
it "can correct encoding from (seemingly) CP850 to Windows-1252" do
|
17
|
+
arg = @arg_win1252_labeled_as_cp850
|
18
|
+
_(arg.encoding).must_equal Encoding::CP850
|
24
19
|
corrected_arg = @parser.correct_encoding(arg)
|
25
|
-
corrected_arg.encoding.must_equal Encoding::Windows_1252
|
20
|
+
_(corrected_arg.encoding).must_equal Encoding::Windows_1252
|
26
21
|
end
|
27
22
|
|
28
|
-
it
|
29
|
-
options = @parser.parse!([@
|
23
|
+
it "encodes (seemingly) CP850 encoded filenames into UTF-8" do
|
24
|
+
options = @parser.parse!([@arg_win1252_labeled_as_cp850])
|
30
25
|
filename = options[:files].first
|
31
|
-
filename.encoding.must_equal Encoding::UTF_8
|
32
|
-
filename.must_equal @arg
|
26
|
+
_(filename.encoding).must_equal Encoding::UTF_8
|
27
|
+
_(filename).must_equal @arg
|
33
28
|
end
|
34
29
|
|
35
|
-
it
|
36
|
-
options = @parser.parse!([@
|
30
|
+
it "encodes Windows-1252 encoded filenames into UTF-8" do
|
31
|
+
options = @parser.parse!([@arg_win1252])
|
37
32
|
filename = options[:files].first
|
38
|
-
filename.encoding.must_equal Encoding::UTF_8
|
39
|
-
filename.must_equal @arg
|
33
|
+
_(filename.encoding).must_equal Encoding::UTF_8
|
34
|
+
_(filename).must_equal @arg
|
40
35
|
end
|
41
36
|
|
42
|
-
it
|
37
|
+
it "encodes UTF-8 encoded filenames into UTF-8" do
|
43
38
|
options = @parser.parse!([@arg])
|
44
39
|
filename = options[:files].first
|
45
|
-
filename.encoding.must_equal Encoding::UTF_8
|
46
|
-
filename.must_equal @arg
|
40
|
+
_(filename.encoding).must_equal Encoding::UTF_8
|
41
|
+
_(filename).must_equal @arg
|
47
42
|
end
|
48
43
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deblank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcus Stollsteimer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
11
|
+
date: 2024-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: deblank is a command line tool that renames files and replaces or removes
|
28
14
|
special characters like spaces, parentheses, or umlauts.
|
29
15
|
email: sto.mar@web.de
|
@@ -32,37 +18,37 @@ executables:
|
|
32
18
|
extensions: []
|
33
19
|
extra_rdoc_files: []
|
34
20
|
files:
|
21
|
+
- Gemfile
|
35
22
|
- README.md
|
36
23
|
- Rakefile
|
24
|
+
- bin/deblank
|
37
25
|
- deblank.gemspec
|
38
26
|
- deblank.h2m
|
39
|
-
- bin/deblank
|
40
27
|
- lib/deblank.rb
|
41
28
|
- man/deblank.1
|
42
29
|
- test/test_nameconverter.rb
|
43
30
|
- test/test_optionparser.rb
|
44
31
|
homepage: https://github.com/stomar/deblank
|
45
32
|
licenses:
|
46
|
-
- GPL-3
|
33
|
+
- GPL-3.0
|
47
34
|
metadata: {}
|
48
35
|
post_install_message:
|
49
36
|
rdoc_options:
|
50
|
-
- --charset=UTF-8
|
37
|
+
- "--charset=UTF-8"
|
51
38
|
require_paths:
|
52
39
|
- lib
|
53
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
41
|
requirements:
|
55
|
-
- -
|
42
|
+
- - ">="
|
56
43
|
- !ruby/object:Gem::Version
|
57
|
-
version: 1.
|
44
|
+
version: 3.1.0
|
58
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
46
|
requirements:
|
60
|
-
- -
|
47
|
+
- - ">="
|
61
48
|
- !ruby/object:Gem::Version
|
62
49
|
version: '0'
|
63
50
|
requirements: []
|
64
|
-
|
65
|
-
rubygems_version: 2.1.9
|
51
|
+
rubygems_version: 3.5.3
|
66
52
|
signing_key:
|
67
53
|
specification_version: 4
|
68
54
|
summary: deblank - remove special characters from filenames
|