filename_cleaner 0.0.1
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 +7 -0
- data/.gitignore +20 -0
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -0
- data/.yardopts +2 -0
- data/Gemfile +4 -0
- data/Guardfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +124 -0
- data/Rakefile +31 -0
- data/bin/filename_cleaner +5 -0
- data/filename_cleaner.gemspec +36 -0
- data/lib/filename_cleaner.rb +4 -0
- data/lib/filename_cleaner/cli.rb +93 -0
- data/lib/filename_cleaner/utils.rb +50 -0
- data/lib/filename_cleaner/version.rb +3 -0
- data/rubocop-todo.yml +92 -0
- data/test/lib/filename_cleaner/test_utils.rb +43 -0
- data/test/test_helper.rb +8 -0
- metadata +249 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c3ab870533d029adaca957481d87548acaec6f39
|
4
|
+
data.tar.gz: c88d4e3ddbd03f8b3a5b2638e5fbdec6e684edc8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 01b5a9c9b5e88ccfa62d9f564a1ad9c361f9abb4b90c8e8c02a469993e7fb52587c670aad9f24b8314d6823df2aa9886d1d0a482cf2bcd5ae932a1a3860a8716
|
7
|
+
data.tar.gz: de1de11622f56a5c2e76478aaf65b8b26e3c911188f237cb11c08c9c42737b6e6235c5b0372dac9f3928ef74ecae2e9df401758449b1d2af038e7e7f74bb207a
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
guard 'minitest' do
|
4
|
+
# with Minitest::Unit
|
5
|
+
watch(%r|^test/(.*)\/?test_(.*)\.rb|)
|
6
|
+
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
7
|
+
watch(%r|^test/test_helper\.rb|) { "test" }
|
8
|
+
|
9
|
+
# with Minitest::Spec
|
10
|
+
# watch(%r|^spec/(.*)_spec\.rb|)
|
11
|
+
# watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
# watch(%r|^spec/spec_helper\.rb|) { "spec" }
|
13
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Burin Choomnuan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
## FilenameClenaer
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/filename_cleaner)
|
4
|
+
|
5
|
+
Remove special characters from a filename using the simple rule. Currently any string that are not one of
|
6
|
+
letters (a..z, A..Z), numbers (0..9), _ (underscore), - (dash), and ' ' spaces string
|
7
|
+
are replaced by the prefered separator char [default to . (dot)].
|
8
|
+
|
9
|
+
### Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'filename_cleaner'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install filename_cleaner
|
22
|
+
|
23
|
+
### Usage
|
24
|
+
|
25
|
+
```sh
|
26
|
+
gem install filename_cleaner
|
27
|
+
filename_cleaner clean
|
28
|
+
```
|
29
|
+
|
30
|
+
#### As command line interface (CLI)
|
31
|
+
|
32
|
+
Just type `filename_cleaner` without any options to see the list of help
|
33
|
+
|
34
|
+
```
|
35
|
+
Usage:
|
36
|
+
filename_cleaner clean
|
37
|
+
|
38
|
+
Options:
|
39
|
+
-b, [--base-dir=BASE_DIR] # Base directory
|
40
|
+
# Default: . (current directory)
|
41
|
+
-e, [--exts=one two three] # List of extensions to search for
|
42
|
+
-f, [--non-exts=one two three] # List of files without extension to search for
|
43
|
+
-n, [--inc-words=one two three] # List of words to be included in the result if any
|
44
|
+
-x, [--exc-words=one two three] # List of words to be excluded from the result if any
|
45
|
+
-i, [--ignore-case], [--no-ignore-case] # Match case insensitively
|
46
|
+
# Default: true
|
47
|
+
-r, [--recursive], [--no-recursive] # Search for files recursively
|
48
|
+
# Default: true
|
49
|
+
-v, [--version], [--no-version] # Display version information
|
50
|
+
-s, [--sep-char=SEP_CHAR] # Separator char to use
|
51
|
+
# Default: .
|
52
|
+
-d, [--dry-run], [--no-dry-run] # Perform a dry run only
|
53
|
+
# Default: true
|
54
|
+
|
55
|
+
Sanitize filename
|
56
|
+
```
|
57
|
+
|
58
|
+
To perform the dry-run without make any changes to the file system:
|
59
|
+
|
60
|
+
```
|
61
|
+
cd ~/projects/files
|
62
|
+
filename_cleaner clean --base-dir . --extes java rb --recursive --sep-char '_'
|
63
|
+
```
|
64
|
+
|
65
|
+
To make your change permanent:
|
66
|
+
|
67
|
+
```
|
68
|
+
cd ~/projects/files
|
69
|
+
filename_cleaner clean --base-dir . --extes java rb --recursive --sep-char '_' --no-dry-run
|
70
|
+
```
|
71
|
+
|
72
|
+
#### As library in your project
|
73
|
+
|
74
|
+
Add this line to your application's Gemfile:
|
75
|
+
|
76
|
+
gem 'filename_cleaner'
|
77
|
+
|
78
|
+
And then execute:
|
79
|
+
|
80
|
+
$ bundle
|
81
|
+
|
82
|
+
Or install it yourself as:
|
83
|
+
|
84
|
+
$ gem install filename_cleaner
|
85
|
+
|
86
|
+
```
|
87
|
+
|
88
|
+
- Use the default separator string '.'
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
require 'filename_cleaner'
|
92
|
+
clean_name = FilenameCleaner::Utils.sanitize_filename('some b@d fil$name.txt')
|
93
|
+
puts clean_name # => 'some.b.d.fil.name.txt'
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
- Specify the separator string
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
require 'filename_cleaner'
|
101
|
+
clean_name = FilenameCleaner::Utils.sanitize_filename('some b@d fil$name.txt', '_')
|
102
|
+
puts clean_name # => 'some_b_d_fil_name.txt'
|
103
|
+
|
104
|
+
```
|
105
|
+
|
106
|
+
### Changelogs
|
107
|
+
|
108
|
+
#### 0.0.1
|
109
|
+
|
110
|
+
- Initial release
|
111
|
+
|
112
|
+
### Contributing
|
113
|
+
|
114
|
+
Bug reports and suggestions for improvements are always welcome,
|
115
|
+
GitHub pull requests are even better!.
|
116
|
+
|
117
|
+
1. Fork it
|
118
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
119
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
120
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
121
|
+
5. Create new Pull Request
|
122
|
+
|
123
|
+
[agile_utils]: https://rubygems.org/gems/agile_utils
|
124
|
+
[rubocop]: https://github.com/bbatsov/rubocop
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
project_name = 'filename_cleaner'
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs << "lib/#{project_name}"
|
8
|
+
t.test_files = FileList["test/lib/#{project_name}/test_*.rb"]
|
9
|
+
t.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :test
|
13
|
+
|
14
|
+
task :pry do
|
15
|
+
require 'pry'
|
16
|
+
require 'awesome_print'
|
17
|
+
require_relative "lib/#{project_name}"
|
18
|
+
include FilenameCleaner
|
19
|
+
ARGV.clear
|
20
|
+
Pry.start
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rubocop/rake_task'
|
24
|
+
desc 'Run RuboCop on the lib directory'
|
25
|
+
Rubocop::RakeTask.new(:rubocop) do |task|
|
26
|
+
task.patterns = ['lib/**/*.rb']
|
27
|
+
# only show the files with failures
|
28
|
+
task.formatters = ['files']
|
29
|
+
# don't abort rake on failure
|
30
|
+
task.fail_on_error = false
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'filename_cleaner/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'filename_cleaner'
|
8
|
+
spec.version = FilenameCleaner::VERSION
|
9
|
+
spec.authors = ['Burin Choomnuan']
|
10
|
+
spec.email = ['agilecreativity@gmail.com']
|
11
|
+
spec.summary = %q{Remove unwanted or special characters from the filename}
|
12
|
+
spec.description = %q{Remove unwanted or special characters from the filename to make the name valid}
|
13
|
+
spec.homepage = 'https://github.com/agilecreativity/filename_cleaner'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'thor', '~> 0.18'
|
22
|
+
spec.add_runtime_dependency 'agile_utils', '~> 0.0.8'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.1'
|
26
|
+
spec.add_development_dependency 'awesome_print', '~> 1.2'
|
27
|
+
spec.add_development_dependency 'minitest-spec-context', '~> 0.0.3'
|
28
|
+
spec.add_development_dependency 'guard-minitest', '~> 2.2'
|
29
|
+
spec.add_development_dependency 'minitest', '~> 4.2'
|
30
|
+
spec.add_development_dependency 'guard', '~> 2.6'
|
31
|
+
spec.add_development_dependency 'pry', '~> 0.9'
|
32
|
+
spec.add_development_dependency 'gem-ctags', '~> 1.0'
|
33
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
34
|
+
spec.add_development_dependency 'rubocop', '~> 0.20'
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'agile_utils'
|
3
|
+
require 'fileutils'
|
4
|
+
require_relative '../filename_cleaner'
|
5
|
+
|
6
|
+
module FilenameCleaner
|
7
|
+
class CLI < Thor
|
8
|
+
desc 'clean', 'Remove special characters in the list of files'
|
9
|
+
method_option *AgileUtils::Options::BASE_DIR
|
10
|
+
method_option *AgileUtils::Options::EXTS
|
11
|
+
method_option *AgileUtils::Options::NON_EXTS
|
12
|
+
method_option *AgileUtils::Options::INC_WORDS
|
13
|
+
method_option *AgileUtils::Options::EXC_WORDS
|
14
|
+
method_option *AgileUtils::Options::IGNORE_CASE
|
15
|
+
method_option *AgileUtils::Options::RECURSIVE
|
16
|
+
method_option *AgileUtils::Options::VERSION
|
17
|
+
|
18
|
+
method_option :sep_char,
|
19
|
+
aliases: '-s',
|
20
|
+
desc: 'Separator char to use',
|
21
|
+
default: '.'
|
22
|
+
|
23
|
+
method_option :dry_run,
|
24
|
+
type: :boolean,
|
25
|
+
aliases: '-d',
|
26
|
+
desc: 'Perform a dry run only',
|
27
|
+
default: true
|
28
|
+
def clean
|
29
|
+
opts = options.symbolize_keys
|
30
|
+
if opts[:version]
|
31
|
+
puts "You are using Filename Cleaner version #{FilenameCleaner::VERSION}"
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
run(opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'usage', 'Display help screen'
|
38
|
+
def usage
|
39
|
+
puts <<-EOS
|
40
|
+
Usage:
|
41
|
+
filename_cleaner clean [OPTIONS]
|
42
|
+
|
43
|
+
Options:
|
44
|
+
-b, [--base-dir=BASE_DIR] # Base directory
|
45
|
+
# Default: . (current directory)
|
46
|
+
-e, [--exts=one two three] # List of extensions to search for
|
47
|
+
-f, [--non-exts=one two three] # List of files without extension to search for
|
48
|
+
-n, [--inc-words=one two three] # List of words to be included in the result if any
|
49
|
+
-x, [--exc-words=one two three] # List of words to be excluded from the result if any
|
50
|
+
-i, [--ignore-case], [--no-ignore-case] # Match case insensitively
|
51
|
+
# Default: true
|
52
|
+
-r, [--recursive], [--no-recursive] # Search for files recursively
|
53
|
+
# Default: true
|
54
|
+
-v, [--version], [--no-version] # Display version information
|
55
|
+
-s, [--sep-char=SEP_CHAR] # Separator char to use
|
56
|
+
# Default: .
|
57
|
+
-d, [--dry-run], [--no-dry-run] # Perform a dry run only
|
58
|
+
# Default: true
|
59
|
+
EOS
|
60
|
+
end
|
61
|
+
|
62
|
+
default_task :usage
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def run(options = {})
|
67
|
+
files = CodeLister.files(options || [])
|
68
|
+
if files.empty?
|
69
|
+
puts "No match found for your options :#{options}"
|
70
|
+
else
|
71
|
+
files.each do |file|
|
72
|
+
dirname = File.dirname(File.expand_path(file))
|
73
|
+
filename = File.basename(file)
|
74
|
+
sanitized_name = FilenameCleaner::Utils.sanitize_filename(filename, options[:sep_char])
|
75
|
+
old_name = File.expand_path(file)
|
76
|
+
new_name = File.expand_path([dirname, sanitized_name].join(File::SEPARATOR))
|
77
|
+
|
78
|
+
if !options[:dry_run]
|
79
|
+
if new_name != old_name
|
80
|
+
puts "FYI: rename #{old_name} -> #{new_name}"
|
81
|
+
FileUtils.mv old_name, new_name
|
82
|
+
else
|
83
|
+
puts "FYI: same file #{old_name}"
|
84
|
+
end
|
85
|
+
else
|
86
|
+
puts 'No changes will be applied as this is a dry-run'
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module FilenameCleaner
|
2
|
+
class Utils
|
3
|
+
DOT = '.'
|
4
|
+
class << self
|
5
|
+
# Sanitize filename that have the extension
|
6
|
+
#
|
7
|
+
# @param [String] filename the input filename with extension
|
8
|
+
# @retyrn [String] the output file with special characters replaced.
|
9
|
+
def sanitize_filename(filename, sep_char = nil)
|
10
|
+
extension = File.extname(filename)
|
11
|
+
|
12
|
+
if extension.empty?
|
13
|
+
replace_dot!(sanitize(filename), sep_char)
|
14
|
+
else
|
15
|
+
name_only = File.basename(filename, ".*")
|
16
|
+
name_only = replace_dot!(sanitize(name_only), sep_char)
|
17
|
+
"#{name_only}#{extension}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Clean the the input string to remove the special characters
|
22
|
+
#
|
23
|
+
# @param [String] filename input file
|
24
|
+
# @return [String] the new file name with special characters replaced or removed.
|
25
|
+
def sanitize(filename)
|
26
|
+
# remove anything that is not letters, numbers, dash, underscore or space
|
27
|
+
# Note: we intentionally ignore dot from the list
|
28
|
+
filename.gsub!(/[^0-9A-Za-z\-_ ]/, DOT)
|
29
|
+
|
30
|
+
# replace multiple occurrences of a given char with a dot
|
31
|
+
['-', '_', ' '].each do |c|
|
32
|
+
filename.gsub!(/#{Regexp.quote(c)}+/, DOT)
|
33
|
+
end
|
34
|
+
|
35
|
+
# replace multiple occurrence of dot with one dot
|
36
|
+
filename.gsub!(/#{Regexp.quote(DOT)}+/, DOT)
|
37
|
+
|
38
|
+
filename
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# replace 'dot' string with a agiven string if any
|
44
|
+
def replace_dot!(string, replace = nil)
|
45
|
+
string.gsub!(/#{Regexp.quote(DOT)}+/, replace) if replace
|
46
|
+
string
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/rubocop-todo.yml
ADDED
@@ -0,0 +1,92 @@
|
|
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
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
describe FilenameCleaner::Utils do
|
3
|
+
context '#sanitize' do
|
4
|
+
it 'works with simple input' do
|
5
|
+
FilenameCleaner::Utils.sanitize('any txt').must_equal 'any.txt'
|
6
|
+
FilenameCleaner::Utils.sanitize('this is a long filename.txt').must_equal 'this.is.a.long.filename.txt'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'works with text with extension' do
|
10
|
+
FilenameCleaner::Utils.sanitize('filename.txt').must_equal 'filename.txt'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
context '#sanitize_filename' do
|
14
|
+
describe 'file with extension' do
|
15
|
+
it 'works with default separator' do
|
16
|
+
FilenameCleaner::Utils.sanitize_filename('some file.txt').must_equal 'some.file.txt'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'works with non-default separator' do
|
20
|
+
FilenameCleaner::Utils.sanitize_filename('some file.txt', '_').must_equal 'some_file.txt'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
describe 'file without extension' do
|
24
|
+
context 'using default separator' do
|
25
|
+
it 'works with simple input' do
|
26
|
+
FilenameCleaner::Utils.sanitize_filename('Gemfile').must_equal 'Gemfile'
|
27
|
+
end
|
28
|
+
it 'works with complex input' do
|
29
|
+
FilenameCleaner::Utils.sanitize_filename('File$without!extension').must_equal 'File.without.extension'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with non-default separator char' do
|
34
|
+
it 'works with simple input' do
|
35
|
+
FilenameCleaner::Utils.sanitize_filename('Gemfile', '_').must_equal 'Gemfile'
|
36
|
+
end
|
37
|
+
it 'works with complex input' do
|
38
|
+
FilenameCleaner::Utils.sanitize_filename('File$without!extension', '-').must_equal 'File-without-extension'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: filename_cleaner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Burin Choomnuan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.18'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.18'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: agile_utils
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.8
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.8
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: awesome_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-spec-context
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.0.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.0.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.2'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4.2'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '4.2'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '2.6'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '2.6'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.9'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.9'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: gem-ctags
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '1.0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '1.0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: yard
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.8'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.8'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rubocop
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0.20'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0.20'
|
195
|
+
description: Remove unwanted or special characters from the filename to make the name
|
196
|
+
valid
|
197
|
+
email:
|
198
|
+
- agilecreativity@gmail.com
|
199
|
+
executables:
|
200
|
+
- filename_cleaner
|
201
|
+
extensions: []
|
202
|
+
extra_rdoc_files: []
|
203
|
+
files:
|
204
|
+
- ".gitignore"
|
205
|
+
- ".rubocop.yml"
|
206
|
+
- ".ruby-version"
|
207
|
+
- ".yardopts"
|
208
|
+
- Gemfile
|
209
|
+
- Guardfile
|
210
|
+
- LICENSE.txt
|
211
|
+
- README.md
|
212
|
+
- Rakefile
|
213
|
+
- bin/filename_cleaner
|
214
|
+
- filename_cleaner.gemspec
|
215
|
+
- lib/filename_cleaner.rb
|
216
|
+
- lib/filename_cleaner/cli.rb
|
217
|
+
- lib/filename_cleaner/utils.rb
|
218
|
+
- lib/filename_cleaner/version.rb
|
219
|
+
- rubocop-todo.yml
|
220
|
+
- test/lib/filename_cleaner/test_utils.rb
|
221
|
+
- test/test_helper.rb
|
222
|
+
homepage: https://github.com/agilecreativity/filename_cleaner
|
223
|
+
licenses:
|
224
|
+
- MIT
|
225
|
+
metadata: {}
|
226
|
+
post_install_message:
|
227
|
+
rdoc_options: []
|
228
|
+
require_paths:
|
229
|
+
- lib
|
230
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
231
|
+
requirements:
|
232
|
+
- - ">="
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: '0'
|
235
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
|
+
requirements:
|
237
|
+
- - ">="
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: '0'
|
240
|
+
requirements: []
|
241
|
+
rubyforge_project:
|
242
|
+
rubygems_version: 2.2.2
|
243
|
+
signing_key:
|
244
|
+
specification_version: 4
|
245
|
+
summary: Remove unwanted or special characters from the filename
|
246
|
+
test_files:
|
247
|
+
- test/lib/filename_cleaner/test_utils.rb
|
248
|
+
- test/test_helper.rb
|
249
|
+
has_rdoc:
|