filename_cleaner 0.3.4 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +94 -2
- data/CHANGELOG.md +20 -0
- data/Gemfile +5 -3
- data/README.md +10 -8
- data/Rakefile +8 -8
- data/bin/filename_cleaner +2 -2
- data/filename_cleaner.gemspec +36 -33
- data/lib/filename_cleaner/cli.rb +59 -29
- data/lib/filename_cleaner/filename_cleaner.rb +7 -7
- data/lib/filename_cleaner/version.rb +1 -1
- data/lib/filename_cleaner.rb +4 -4
- metadata +5 -5
- data/rubocop-todo.yml +0 -92
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b04aedac1b86a7a5717c4ca522de227f89a4ed2
|
4
|
+
data.tar.gz: 8e4be2b22531948dcc42bca0be26474aab99bed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bc5d71698af113952dc221d3418227bd137107a5c500152dc4cc41ebc56611156a8d1648fbb373700beb0eb63e2b5a4766244629dac99ddba7823e3c09a9bbe
|
7
|
+
data.tar.gz: 6f6a7ad4a6258379c48da507ac1d7b3ad3724d7f0d922a96f55be0d49e46e0f721009ed484fc21adb06af2eaea441b8cbdc10a2b7a8348627e163c60500d27fc
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,95 @@
|
|
1
|
-
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- Gemfile
|
4
|
+
- Rakefile
|
5
|
+
- bin/*
|
6
|
+
- filename_cleaner.gemspec
|
7
|
+
- lib/**/*.rb
|
8
|
+
- test/**/*.rb
|
9
|
+
# Avoid long parameter lists
|
10
|
+
ParameterLists:
|
11
|
+
Max: 5
|
12
|
+
CountKeywordArgs: true
|
2
13
|
|
3
|
-
|
14
|
+
MethodLength:
|
15
|
+
CountComments: false
|
16
|
+
Max: 15
|
17
|
+
|
18
|
+
# Avoid more than `Max` levels of nesting.
|
19
|
+
BlockNesting:
|
20
|
+
Max: 4
|
21
|
+
|
22
|
+
# Align with the style guide.
|
23
|
+
CollectionMethods:
|
24
|
+
PreferredMethods:
|
25
|
+
collect: 'map'
|
26
|
+
inject: 'reduce'
|
27
|
+
find: 'detect'
|
28
|
+
find_all: 'select'
|
29
|
+
|
30
|
+
# Do not force public/protected/private keyword to be indented at the same
|
31
|
+
# level as the def keyword. My personal preference is to outdent these keywords
|
32
|
+
# because I think when scanning code it makes it easier to identify the
|
33
|
+
# sections of code and visually separate them. When the keyword is at the same
|
34
|
+
# level I think it sort of blends in with the def keywords and makes it harder
|
35
|
+
# to scan the code and see where the sections are.
|
36
|
+
AccessModifierIndentation:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
# Limit line length
|
40
|
+
LineLength:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
# Disable documentation checking until a class needs to be documented once
|
44
|
+
Documentation:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
# Enforce Ruby 1.8-compatible hash syntax
|
48
|
+
HashSyntax:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
# No spaces inside hash literals
|
52
|
+
SpaceInsideHashLiteralBraces:
|
53
|
+
EnforcedStyle: no_space
|
54
|
+
|
55
|
+
# Allow dots at the end of lines
|
56
|
+
DotPosition:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
# Don't require magic comment at the top of every file
|
60
|
+
Encoding:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
# Enforce outdenting of access modifiers (i.e. public, private, protected)
|
64
|
+
AccessModifierIndentation:
|
65
|
+
EnforcedStyle: outdent
|
66
|
+
|
67
|
+
EmptyLinesAroundAccessModifier:
|
68
|
+
Enabled: true
|
69
|
+
|
70
|
+
# Align ends correctly
|
71
|
+
EndAlignment:
|
72
|
+
AlignWith: variable
|
73
|
+
|
74
|
+
# Indentation of when/else
|
75
|
+
CaseIndentation:
|
76
|
+
IndentWhenRelativeTo: end
|
77
|
+
IndentOneStep: false
|
78
|
+
|
79
|
+
DoubleNegation:
|
80
|
+
Enabled: false
|
81
|
+
|
82
|
+
PercentLiteralDelimiters:
|
83
|
+
PreferredDelimiters:
|
84
|
+
'%': ()
|
85
|
+
'%i': ()
|
86
|
+
'%q': ()
|
87
|
+
'%Q': ()
|
88
|
+
'%r': '{}'
|
89
|
+
'%s': ()
|
90
|
+
'%w': '[]'
|
91
|
+
'%W': '[]'
|
92
|
+
'%x': ()
|
93
|
+
|
94
|
+
StringLiterals:
|
95
|
+
EnforcedStyle: double_quotes
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
### 0.3.6
|
2
|
+
|
3
|
+
* Fix the bugs that were introduced in 0.3.5 that caused the file to be renamed
|
4
|
+
incorrectly.
|
5
|
+
* Add `--downcase` option to make lower case each word in the filename
|
6
|
+
* Add `--capitalize` option to capitalize each word in the filename
|
7
|
+
* Make `_` underscore the default value for `--sep-string`
|
8
|
+
* Remove less used optons
|
9
|
+
- Remove `--inc-words` option!
|
10
|
+
- Remove `--exc-words` option!
|
11
|
+
- Remove `--ignore-case` option!
|
12
|
+
* Consistently use double quote for string
|
13
|
+
* Update Coverall configuration
|
14
|
+
- add `.coveralls.yml`
|
15
|
+
- adjust the settings in `test/test_helper.rb`
|
16
|
+
|
17
|
+
### 0.3.5
|
18
|
+
|
19
|
+
* Yank - due to one bug that cause the files to be renamed incorrectly!
|
20
|
+
|
1
21
|
### 0.3.4
|
2
22
|
|
3
23
|
* Code refactoring
|
data/Gemfile
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
source
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in file_indexer.gemspec
|
1
|
+
source "https://rubygems.org"
|
2
|
+
# Specify your gem's dependencies in filename_cleaner.gemspec
|
4
3
|
gemspec
|
4
|
+
|
5
|
+
# Note: may be just add to to the filename_cleaner.gemspec
|
6
|
+
gem 'coveralls', require: false
|
data/README.md
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
[![Dependency Status](https://gemnasium.com/agilecreativity/filename_cleaner.png)][gemnasium]
|
5
5
|
[![Code Climate](https://codeclimate.com/github/agilecreativity/filename_cleaner.png)][codeclimate]
|
6
6
|
[![Build Status](https://secure.travis-ci.org/agilecreativity/filename_cleaner.png)][travis-ci]
|
7
|
-
[![Coverage Status](https://
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/agilecreativity/filename_cleaner/badge.png?branch=master)][coveralls]
|
8
8
|
|
9
9
|
[gem]: http://badge.fury.io/rb/filename_cleaner
|
10
10
|
[gemnasium]: https://gemnasium.com/agilecreativity/filename_cleaner
|
11
11
|
[codeclimate]: https://codeclimate.com/github/agilecreativity/filename_cleaner
|
12
12
|
[travis-ci]: http://travis-ci.org/agilecreativity/filename_cleaner
|
13
|
-
[coveralls]: https://coveralls.io/r/agilecreativity/filename_cleaner
|
13
|
+
[coveralls]: https://coveralls.io/r/agilecreativity/filename_cleaner?branch=master
|
14
14
|
|
15
15
|
Quickly rename list of files with extension and replace any special characters with
|
16
16
|
with any given string.
|
@@ -37,16 +37,18 @@ Options:
|
|
37
37
|
-b, [--base-dir=BASE_DIR] # Base directory
|
38
38
|
# Default: . (current directory)
|
39
39
|
-e, [--exts=one two three] # List of extensions to search for
|
40
|
-
-n, [--inc-words=one two three] # List of words to be included in the result if any
|
41
|
-
-x, [--exc-words=one two three] # List of words to be excluded from the result if any
|
42
|
-
-i, [--ignore-case], [--no-ignore-case] # Match case insensitively
|
43
|
-
# Default: true
|
44
40
|
-r, [--recursive], [--no-recursive] # Search for files recursively
|
45
41
|
# Default: true
|
46
|
-
-v, [--version], [--no-version] # Display version information
|
47
42
|
-s, [--sep-char=SEP_CHAR] # Separator char to use
|
48
|
-
# Default:
|
43
|
+
# Default: _
|
44
|
+
-d, [--downcase], [--no-downcase] # Convert each word int the filename to lowercase
|
45
|
+
# Default: --no-downcase
|
46
|
+
-t, [--capitalize], [--no-capitalize] # Capitalize each word in the filename
|
47
|
+
# Default: --no-capitalize
|
49
48
|
-c, [--commit], [--no-commit] # Commit your changes
|
49
|
+
# Default: --no-commit
|
50
|
+
-v, [--version], [--no-version] # Display version information
|
51
|
+
# Default: --no-version
|
50
52
|
|
51
53
|
Sanitize and rename file with special characters
|
52
54
|
```
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rake/testtask"
|
3
3
|
|
4
|
-
project_name =
|
4
|
+
project_name = "filename_cleaner"
|
5
5
|
|
6
6
|
Rake::TestTask.new do |t|
|
7
7
|
t.libs << "lib/#{project_name}"
|
@@ -9,23 +9,23 @@ Rake::TestTask.new do |t|
|
|
9
9
|
t.verbose = true
|
10
10
|
end
|
11
11
|
|
12
|
-
task :
|
12
|
+
task default: :test
|
13
13
|
|
14
14
|
task :pry do
|
15
|
-
require
|
16
|
-
require
|
15
|
+
require "pry"
|
16
|
+
require "awesome_print"
|
17
17
|
require_relative "lib/#{project_name}"
|
18
18
|
include FilenameCleaner
|
19
19
|
ARGV.clear
|
20
20
|
Pry.start
|
21
21
|
end
|
22
22
|
|
23
|
-
require
|
24
|
-
desc
|
23
|
+
require "rubocop/rake_task"
|
24
|
+
desc "Run RuboCop on the lib directory"
|
25
25
|
Rubocop::RakeTask.new(:rubocop) do |task|
|
26
|
-
task.patterns = [
|
26
|
+
task.patterns = ["lib/**/*.rb"]
|
27
27
|
# only show the files with failures
|
28
|
-
task.formatters = [
|
28
|
+
task.formatters = ["files"]
|
29
29
|
# don't abort rake on failure
|
30
30
|
task.fail_on_error = false
|
31
31
|
end
|
data/bin/filename_cleaner
CHANGED
data/filename_cleaner.gemspec
CHANGED
@@ -1,41 +1,44 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "filename_cleaner/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = "filename_cleaner"
|
8
8
|
spec.version = FilenameCleaner::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary = %q
|
12
|
-
spec.description = %q
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
9
|
+
spec.authors = ["Burin Choomnuan"]
|
10
|
+
spec.email = ["agilecreativity@gmail.com"]
|
11
|
+
spec.summary = %q(Bulk rename/remove unwanted characters from list of files in any directory recursively)
|
12
|
+
spec.description = %q(
|
13
|
+
Bulk rename and remove unwanted characters from list of files in any directory recursively.
|
14
|
+
Turn something like 'my_#$@#$_bad_$!@_filename!!.txt' into 'my_bad_filename.txt'
|
15
|
+
).gsub(/^\s+/, " ")
|
16
|
+
spec.homepage = "https://github.com/agilecreativity/filename_cleaner"
|
17
|
+
spec.license = "MIT"
|
18
|
+
spec.files = Dir.glob("{bin,lib}/**/*") +
|
19
|
+
%w[Gemfile
|
20
|
+
Rakefile
|
21
|
+
filename_cleaner.gemspec
|
22
|
+
README.md
|
23
|
+
CHANGELOG.md
|
24
|
+
LICENSE
|
25
|
+
.rubocop.yml
|
26
|
+
.gitignore]
|
24
27
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
28
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
26
|
-
spec.require_paths = [
|
27
|
-
spec.add_runtime_dependency
|
28
|
-
spec.add_runtime_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency
|
40
|
-
spec.add_development_dependency
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
spec.add_runtime_dependency "thor", "~> 0.19"
|
31
|
+
spec.add_runtime_dependency "agile_utils", "~> 0.1"
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
34
|
+
spec.add_development_dependency "awesome_print", "~> 1.2"
|
35
|
+
spec.add_development_dependency "minitest-spec-context", "~> 0.0.3"
|
36
|
+
spec.add_development_dependency "guard-minitest", "~> 2.2"
|
37
|
+
spec.add_development_dependency "minitest", "~> 5.3"
|
38
|
+
spec.add_development_dependency "guard", "~> 2.6"
|
39
|
+
spec.add_development_dependency "pry", "~> 0.9"
|
40
|
+
spec.add_development_dependency "gem-ctags", "~> 1.0"
|
41
|
+
spec.add_development_dependency "yard", "~> 0.8"
|
42
|
+
spec.add_development_dependency "rubocop", "~> 0.20"
|
43
|
+
spec.add_development_dependency "coveralls", "~> 0.7"
|
41
44
|
end
|
data/lib/filename_cleaner/cli.rb
CHANGED
@@ -1,26 +1,33 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require_relative
|
1
|
+
require "thor"
|
2
|
+
require "agile_utils"
|
3
|
+
require "fileutils"
|
4
|
+
require_relative "../filename_cleaner"
|
5
5
|
module FilenameCleaner
|
6
6
|
class CLI < Thor
|
7
7
|
# rubocop:disable AmbiguousOperator, LineLength
|
8
|
-
desc
|
8
|
+
desc "rename", "Sanitize and rename file with special characters"
|
9
9
|
method_option *AgileUtils::Options::BASE_DIR
|
10
10
|
method_option *AgileUtils::Options::EXTS
|
11
|
-
method_option *AgileUtils::Options::INC_WORDS
|
12
|
-
method_option *AgileUtils::Options::EXC_WORDS
|
13
|
-
method_option *AgileUtils::Options::IGNORE_CASE
|
14
11
|
method_option *AgileUtils::Options::RECURSIVE
|
15
12
|
method_option *AgileUtils::Options::VERSION
|
16
13
|
method_option :sep_char,
|
17
|
-
aliases:
|
18
|
-
desc:
|
19
|
-
default:
|
14
|
+
aliases: "-s",
|
15
|
+
desc: "Separator char to use",
|
16
|
+
default: "_"
|
17
|
+
method_option :downcase,
|
18
|
+
type: :boolean,
|
19
|
+
aliases: "-d",
|
20
|
+
desc: "Convert each word int the filename to lowercase",
|
21
|
+
default: false
|
22
|
+
method_option :capitalize,
|
23
|
+
type: :boolean,
|
24
|
+
aliases: "-t",
|
25
|
+
desc: "Capitalize each word in the filename",
|
26
|
+
default: false
|
20
27
|
method_option :commit,
|
21
28
|
type: :boolean,
|
22
|
-
aliases:
|
23
|
-
desc:
|
29
|
+
aliases: "-c",
|
30
|
+
desc: "Commit your changes",
|
24
31
|
default: false
|
25
32
|
def rename
|
26
33
|
opts = options.symbolize_keys
|
@@ -31,7 +38,7 @@ module FilenameCleaner
|
|
31
38
|
sanitize_and_rename(opts)
|
32
39
|
end
|
33
40
|
|
34
|
-
desc
|
41
|
+
desc "usage", "Display help screen"
|
35
42
|
def usage
|
36
43
|
puts <<-EOS
|
37
44
|
Usage:
|
@@ -39,18 +46,20 @@ Usage:
|
|
39
46
|
|
40
47
|
Options:
|
41
48
|
-b, [--base-dir=BASE_DIR] # Base directory
|
42
|
-
# Default: . (current directory
|
49
|
+
# Default: . (current directory)
|
43
50
|
-e, [--exts=one two three] # List of extensions to search for
|
44
|
-
-n, [--inc-words=one two three] # List of words to be included in the result if any
|
45
|
-
-x, [--exc-words=one two three] # List of words to be excluded from the result if any
|
46
|
-
-i, [--ignore-case], [--no-ignore-case] # Match case insensitively
|
47
|
-
# Default: true
|
48
51
|
-r, [--recursive], [--no-recursive] # Search for files recursively
|
49
52
|
# Default: true
|
50
|
-
-v, [--version], [--no-version] # Display version information
|
51
53
|
-s, [--sep-char=SEP_CHAR] # Separator char to use
|
52
|
-
# Default:
|
54
|
+
# Default: _
|
55
|
+
-d, [--downcase], [--no-downcase] # Convert each word int the filename to lowercase
|
56
|
+
# Default: --no-downcase
|
57
|
+
-t, [--capitalize], [--no-capitalize] # Capitalize each word in the filename
|
58
|
+
# Default: --no-capitalize
|
53
59
|
-c, [--commit], [--no-commit] # Commit your changes
|
60
|
+
# Default: --no-commit
|
61
|
+
-v, [--version], [--no-version] # Display version information
|
62
|
+
# Default: --no-version
|
54
63
|
|
55
64
|
Sanitize and rename file with special characters
|
56
65
|
EOS
|
@@ -58,8 +67,9 @@ Sanitize and rename file with special characters
|
|
58
67
|
# rubocop:enable AmbiguousOperator, LineLength
|
59
68
|
default_task :usage
|
60
69
|
|
61
|
-
|
70
|
+
private
|
62
71
|
|
72
|
+
# rubocop:disable LineLength
|
63
73
|
def sanitize_and_rename(options = {})
|
64
74
|
files = CodeLister.files(options)
|
65
75
|
if files.empty?
|
@@ -69,24 +79,44 @@ Sanitize and rename file with special characters
|
|
69
79
|
puts "FYI: process : #{index + 1} of #{files.size}"
|
70
80
|
dirname = File.dirname(File.expand_path(file))
|
71
81
|
filename = File.basename(file)
|
72
|
-
|
82
|
+
new_name = formatted_name(filename, options)
|
73
83
|
old_name = File.expand_path(file)
|
74
|
-
new_name = File.expand_path([dirname,
|
84
|
+
new_name = File.expand_path([dirname, new_name].join(File::SEPARATOR))
|
75
85
|
compare_and_rename(old_name, new_name, options[:commit])
|
76
86
|
end
|
77
87
|
unless options[:commit]
|
78
|
-
puts
|
79
|
-
puts
|
80
|
-
puts
|
88
|
+
puts "--------------------------------------------------------------"
|
89
|
+
puts "This is a dry run, to commit your change, please use --commit option"
|
90
|
+
puts "--------------------------------------------------------------"
|
81
91
|
end
|
82
92
|
end
|
83
93
|
end
|
94
|
+
# rubocop:enable LineLength
|
84
95
|
|
85
|
-
def
|
96
|
+
def formatted_name(filename, options)
|
97
|
+
sep_char = options[:sep_char]
|
98
|
+
sanitized_name = FilenameCleaner.sanitize(filename, sep_char, true)
|
99
|
+
|
100
|
+
# First split the two part so that only name is used!
|
101
|
+
basename = File.basename(sanitized_name, ".*")
|
102
|
+
extname = File.extname(sanitized_name)
|
103
|
+
if options[:downcase]
|
104
|
+
basename = basename.split(sep_char).map(&:downcase).join(sep_char)
|
105
|
+
end
|
106
|
+
if options[:capitalize]
|
107
|
+
basename= basename.split(sep_char).map(&:capitalize).join(sep_char)
|
108
|
+
end
|
109
|
+
"#{basename}#{extname}"
|
110
|
+
end
|
111
|
+
|
112
|
+
def compare_and_rename(old_name, new_name, commit)
|
86
113
|
if new_name != old_name
|
87
114
|
puts "FYI: old name: #{old_name}"
|
88
115
|
puts "FYI: new name: #{new_name}"
|
89
|
-
|
116
|
+
# Don't override the file if it is already exist!
|
117
|
+
unless File.exist?(new_name) || !commit
|
118
|
+
FileUtils.mv old_name, new_name
|
119
|
+
end
|
90
120
|
else
|
91
121
|
puts "FYI: same file #{old_name}"
|
92
122
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module FilenameCleaner
|
2
|
-
DOT =
|
2
|
+
DOT = "."
|
3
3
|
class << self
|
4
4
|
# Sanitize the any name with or without any extension
|
5
5
|
#
|
6
6
|
# @param [String] name the input string
|
7
7
|
# @param [String] sep_char the separator char to be used
|
8
8
|
# @return [String] output string with special chars replaced withe specified string
|
9
|
-
def sanitize(name, sep_char =
|
9
|
+
def sanitize(name, sep_char = ".", have_extension = false)
|
10
10
|
if have_extension
|
11
11
|
sanitize_name_with_extension(name, sep_char)
|
12
12
|
else
|
@@ -14,14 +14,14 @@ module FilenameCleaner
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
private
|
18
18
|
|
19
19
|
# Sanitize the any name with or without any extension
|
20
20
|
#
|
21
21
|
# @param [String] name the input string
|
22
22
|
# @param [String] sep_char the separator char to be used
|
23
23
|
# @return [String] output string with special chars replaced withe specified string
|
24
|
-
def sanitize_name_without_extension(name, sep_char =
|
24
|
+
def sanitize_name_without_extension(name, sep_char = ".")
|
25
25
|
replace_dot(sanitize_with_dot(name), sep_char)
|
26
26
|
end
|
27
27
|
|
@@ -29,7 +29,7 @@ module FilenameCleaner
|
|
29
29
|
#
|
30
30
|
# @param [String] name the input filename with extension
|
31
31
|
# @return [String] the output file with special characters replaced
|
32
|
-
def sanitize_name_with_extension(name, sep_char =
|
32
|
+
def sanitize_name_with_extension(name, sep_char = ".")
|
33
33
|
extension = File.extname(name)
|
34
34
|
name_only = File.basename(name, ".*")
|
35
35
|
name_only = replace_dot(sanitize_with_dot(name_only), sep_char)
|
@@ -45,7 +45,7 @@ module FilenameCleaner
|
|
45
45
|
name.gsub!(/[^0-9A-Za-z\-_ ]/, DOT)
|
46
46
|
|
47
47
|
# Replace multiple occurrences of a given character with a dot
|
48
|
-
[
|
48
|
+
["-", "_", " "].each do |c|
|
49
49
|
name.gsub!(/#{Regexp.quote(c)}+/, DOT)
|
50
50
|
end
|
51
51
|
|
@@ -53,7 +53,7 @@ module FilenameCleaner
|
|
53
53
|
name.gsub!(/#{Regexp.quote(DOT)}+/, DOT)
|
54
54
|
|
55
55
|
# Remove the last char if it is a dot
|
56
|
-
name.gsub!(/\.$/,
|
56
|
+
name.gsub!(/\.$/, "") if name[-1] == DOT
|
57
57
|
|
58
58
|
# return the result
|
59
59
|
name
|
data/lib/filename_cleaner.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
3
|
-
require_relative
|
4
|
-
require_relative
|
1
|
+
require_relative "./filename_cleaner/version"
|
2
|
+
require_relative "./filename_cleaner/cli"
|
3
|
+
require_relative "./filename_cleaner/filename_cleaner"
|
4
|
+
require_relative "./filename_cleaner/core_ext/object/blank"
|
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.6
|
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-05-
|
11
|
+
date: 2014-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -206,8 +206,9 @@ dependencies:
|
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0.7'
|
209
|
-
description: Bulk rename and remove unwanted characters from list of files in any
|
210
|
-
directory recursively
|
209
|
+
description: " Bulk rename and remove unwanted characters from list of files in any
|
210
|
+
directory recursively.\n Turn something like 'my_#$@#$_bad_$!@_filename!!.txt' into
|
211
|
+
'my_bad_filename.txt'\n "
|
211
212
|
email:
|
212
213
|
- agilecreativity@gmail.com
|
213
214
|
executables:
|
@@ -229,7 +230,6 @@ files:
|
|
229
230
|
- lib/filename_cleaner/core_ext/object/blank.rb
|
230
231
|
- lib/filename_cleaner/filename_cleaner.rb
|
231
232
|
- lib/filename_cleaner/version.rb
|
232
|
-
- rubocop-todo.yml
|
233
233
|
homepage: https://github.com/agilecreativity/filename_cleaner
|
234
234
|
licenses:
|
235
235
|
- MIT
|
data/rubocop-todo.yml
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2014-04-23 16:41:01 +1000 using RuboCop version 0.19.1.
|
3
|
-
# The point is for the user to remove these configuration records
|
4
|
-
# one by one as the offenses are removed from the code base.
|
5
|
-
# Note that changes in the inspected code, or installation of new
|
6
|
-
# versions of RuboCop, may require this file to be generated again.
|
7
|
-
|
8
|
-
# Offense count: 2
|
9
|
-
# Cop supports --auto-correct.
|
10
|
-
DeprecatedClassMethods:
|
11
|
-
Enabled: false
|
12
|
-
|
13
|
-
# Offense count: 9
|
14
|
-
Documentation:
|
15
|
-
Enabled: false
|
16
|
-
|
17
|
-
# Offense count: 6
|
18
|
-
# Cop supports --auto-correct.
|
19
|
-
EmptyLinesAroundBody:
|
20
|
-
Enabled: false
|
21
|
-
|
22
|
-
# Offense count: 1
|
23
|
-
Eval:
|
24
|
-
Enabled: false
|
25
|
-
|
26
|
-
# Offense count: 2
|
27
|
-
# Configuration parameters: Exclude.
|
28
|
-
FileName:
|
29
|
-
Enabled: false
|
30
|
-
|
31
|
-
# Offense count: 1
|
32
|
-
# Cop supports --auto-correct.
|
33
|
-
IndentationConsistency:
|
34
|
-
Enabled: true
|
35
|
-
|
36
|
-
# Offense count: 2
|
37
|
-
# Cop supports --auto-correct.
|
38
|
-
LeadingCommentSpace:
|
39
|
-
Enabled: false
|
40
|
-
|
41
|
-
# Offense count: 5
|
42
|
-
LineLength:
|
43
|
-
Max: 89
|
44
|
-
|
45
|
-
# Offense count: 1
|
46
|
-
# Configuration parameters: CountComments.
|
47
|
-
MethodLength:
|
48
|
-
Max: 12
|
49
|
-
|
50
|
-
# Offense count: 2
|
51
|
-
# Configuration parameters: NamePrefixBlacklist.
|
52
|
-
PredicateName:
|
53
|
-
Enabled: false
|
54
|
-
|
55
|
-
# Offense count: 1
|
56
|
-
RedundantBegin:
|
57
|
-
Enabled: true
|
58
|
-
|
59
|
-
# Offense count: 1
|
60
|
-
RescueException:
|
61
|
-
Enabled: false
|
62
|
-
|
63
|
-
# Offense count: 2
|
64
|
-
RescueModifier:
|
65
|
-
Enabled: false
|
66
|
-
|
67
|
-
# Offense count: 2
|
68
|
-
# Cop supports --auto-correct.
|
69
|
-
SpaceAfterComma:
|
70
|
-
Enabled: false
|
71
|
-
|
72
|
-
# Offense count: 2
|
73
|
-
# Cop supports --auto-correct.
|
74
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
75
|
-
SpaceBeforeBlockBraces:
|
76
|
-
Enabled: false
|
77
|
-
|
78
|
-
# Offense count: 1
|
79
|
-
# Cop supports --auto-correct.
|
80
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
81
|
-
SpaceInsideBlockBraces:
|
82
|
-
Enabled: true
|
83
|
-
|
84
|
-
# Offense count: 16
|
85
|
-
# Cop supports --auto-correct.
|
86
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
87
|
-
StringLiterals:
|
88
|
-
Enabled: false
|
89
|
-
|
90
|
-
# Offense count: 2
|
91
|
-
UselessAssignment:
|
92
|
-
Enabled: true
|