filename_cleaner 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +6 -0
- data/lib/filename_cleaner/cli.rb +1 -17
- data/lib/filename_cleaner/filename_cleaner.rb +27 -1
- data/lib/filename_cleaner/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35445207a901cb122ba596e958a996cd819bdebb
|
4
|
+
data.tar.gz: 69467588b5aba6e7996e76db86231f45ffc57aaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e41225111100cc8df68b16b19e9b6df8140ba91156cd0f27b5ba305225b35f264dbaa438543f5e0a311ed515e32506176735ef3531dae605a845a5a11da4784e
|
7
|
+
data.tar.gz: b342996a7c09770e73063a78b927989c05e393c048951ac726e3f18dd3e754d26fd3dce82cb37a235b3d69293dfa134d6d4cdda3eb27c3fc1baf446c42071cca
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -19,6 +19,12 @@ Currently any string that are not one of letters (a..z, A..Z),
|
|
19
19
|
numbers (0..9), _ (underscore), - (dash), and ' ' spaces string
|
20
20
|
are first squeezed into one string and then replaced by any given string/char [default to . (a single dot)].
|
21
21
|
|
22
|
+
Optionally, you could also
|
23
|
+
|
24
|
+
- capitalized each word in the output
|
25
|
+
- make each word in output lower case
|
26
|
+
- use more than one character as the separator string if you prefer
|
27
|
+
|
22
28
|
### Installation
|
23
29
|
|
24
30
|
```sh
|
data/lib/filename_cleaner/cli.rb
CHANGED
@@ -78,7 +78,7 @@ Sanitize and rename file with special characters
|
|
78
78
|
puts "FYI: process : #{index + 1} of #{files.size}"
|
79
79
|
dirname = File.dirname(File.expand_path(file))
|
80
80
|
filename = File.basename(file)
|
81
|
-
new_name = formatted_name(filename, options)
|
81
|
+
new_name = FilenameCleaner.formatted_name(filename, options)
|
82
82
|
old_name = File.expand_path(file)
|
83
83
|
new_name = File.expand_path([dirname, new_name].join(File::SEPARATOR))
|
84
84
|
compare_and_rename(old_name, new_name, options[:commit])
|
@@ -92,22 +92,6 @@ Sanitize and rename file with special characters
|
|
92
92
|
end
|
93
93
|
# rubocop:enable LineLength
|
94
94
|
|
95
|
-
def formatted_name(filename, options)
|
96
|
-
sep_char = options[:sep_char]
|
97
|
-
sanitized_name = FilenameCleaner.sanitize(filename, sep_char, true)
|
98
|
-
|
99
|
-
# First split the two part so that only name is used!
|
100
|
-
basename = File.basename(sanitized_name, ".*")
|
101
|
-
extname = File.extname(sanitized_name)
|
102
|
-
if options[:downcase]
|
103
|
-
basename = basename.split(sep_char).map(&:downcase).join(sep_char)
|
104
|
-
end
|
105
|
-
if options[:capitalize]
|
106
|
-
basename= basename.split(sep_char).map(&:capitalize).join(sep_char)
|
107
|
-
end
|
108
|
-
"#{basename}#{extname}"
|
109
|
-
end
|
110
|
-
|
111
95
|
def compare_and_rename(old_name, new_name, commit)
|
112
96
|
if new_name != old_name
|
113
97
|
puts "FYI: old name: #{old_name}"
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module FilenameCleaner
|
2
2
|
DOT = "."
|
3
3
|
class << self
|
4
|
-
# Sanitize the any name with or without
|
4
|
+
# Sanitize the any name with or without extension
|
5
5
|
#
|
6
6
|
# @param [String] name the input string
|
7
7
|
# @param [String] sep_char the separator char to be used
|
8
|
+
# @param [Boolean] have_extension indicate if the the input file should be
|
9
|
+
# treated as having extension or not having one
|
8
10
|
# @return [String] output string with special chars replaced withe specified string
|
9
11
|
def sanitize(name, sep_char = ".", have_extension = false)
|
10
12
|
if have_extension
|
@@ -14,6 +16,30 @@ module FilenameCleaner
|
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
19
|
+
# Get formatted name for existing file
|
20
|
+
#
|
21
|
+
# @param [String] filename the input filename
|
22
|
+
# @param [Hash<Symbol, Object>] opts the hash value for options to be applied
|
23
|
+
#
|
24
|
+
# @option opts [String] :sep_char The separator string
|
25
|
+
# @option opts [Boolean] :downcase Convert each word to lower case
|
26
|
+
# @option opts [Boolean] :capitalize: Capitalize each word in the name
|
27
|
+
def formatted_name(filename, opts = {})
|
28
|
+
sep_char = opts[:sep_char] || "."
|
29
|
+
sanitized_name = FilenameCleaner.sanitize(filename, sep_char, true)
|
30
|
+
|
31
|
+
# First split the two part so that only name is used!
|
32
|
+
basename = File.basename(sanitized_name, ".*")
|
33
|
+
extname = File.extname(sanitized_name)
|
34
|
+
if opts[:downcase]
|
35
|
+
basename = basename.split(sep_char).map(&:downcase).join(sep_char)
|
36
|
+
end
|
37
|
+
if opts[:capitalize]
|
38
|
+
basename= basename.split(sep_char).map(&:capitalize).join(sep_char)
|
39
|
+
end
|
40
|
+
"#{basename}#{extname}"
|
41
|
+
end
|
42
|
+
|
17
43
|
private
|
18
44
|
|
19
45
|
# Sanitize the any name with or without any extension
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filename_cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burin Choomnuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|