filename_cleaner 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cdac07fa184d53eded2bdebcbfa1e362d90bbd14
4
- data.tar.gz: f34bb1e4fd166d5d34ff20971d83512e5e027b27
3
+ metadata.gz: ba0764b038df0404b93814f17a7309ada921ccf4
4
+ data.tar.gz: 1c6f72706886d64a1d895d221049c4da92b78cb6
5
5
  SHA512:
6
- metadata.gz: a599a4effdd5bdedc43410d7e80852b1570cf877f6d4581820473c98ff3d3fadf9f970502a1709970bd1a14a46447b659a9ca94f2032a07676e7a2bf2590bdcb
7
- data.tar.gz: eb4b943621f94faaf3c20327c5bfe6ed690100ce048d1a3e081ee502bb06a6a50b938c9793eff164ac837b24134c43db5db1a0efb0c052aeb9f51fbea366c7da
6
+ metadata.gz: 0ebc349f1f3a7bf4920086b78a588b65c48a9a1f8824454ebaad7f067ec343b25f4afd6411c8d9081a22d5ae6fcf2591d30fdc03bc0e410baaded9f9c3ae543a
7
+ data.tar.gz: 208964761eb2829daa8be48bcbe1d4d10dd17b5ed8bd7cac10363aac316b302d2f88ebc5709e44a9b520e570168bad863cd00cf05ae0c57ae481b1d97bd2067f
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.1.2
@@ -0,0 +1,25 @@
1
+ ### Changelogs
2
+
3
+ #### 0.1.1
4
+
5
+ - Remove the last char from the filename if it is not numbers or letters
6
+
7
+ #### 0.1.0
8
+
9
+ - First [Semantic Versioning][] version.
10
+
11
+ #### 0.0.3
12
+
13
+ - Remove the namespace and code refactoring
14
+
15
+ #### 0.0.2
16
+
17
+ - Update gem dependencies to the latest version
18
+ - Update gemspec to reflect the actual feature of the gem
19
+ - Update and cleanup README.md
20
+
21
+ #### 0.0.1
22
+
23
+ - Initial release
24
+
25
+ [Semantic Versioning]: http://semver.org
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ## Filename Cleaner
1
+ ## filename_cleaner
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/filename_cleaner.svg)](http://badge.fury.io/rb/filename_cleaner)
4
4
  [![Dependency Status](https://gemnasium.com/agilecreativity/filename_cleaner.png)](https://gemnasium.com/agilecreativity/filename_cleaner)
@@ -93,22 +93,6 @@ puts clean_name # => 'some_b_d_fil_name.txt'
93
93
 
94
94
  ```
95
95
 
96
- ### Changelogs
97
-
98
- #### 0.0.3
99
-
100
- - Remove the namespace and code refactoring
101
-
102
- #### 0.0.2
103
-
104
- - Update gem dependencies to the latest version
105
- - Update gemspec to reflect the actual feature of the gem
106
- - Update and cleanup README.md
107
-
108
- #### 0.0.1
109
-
110
- - Initial release
111
-
112
96
  ### Contributing
113
97
 
114
98
  Bug reports and suggestions for improvements are always welcome,
@@ -68,7 +68,8 @@ Options:
68
68
  if files.empty?
69
69
  puts "No match found for your options :#{options}"
70
70
  else
71
- files.each do |file|
71
+ files.each_with_index do |file, index|
72
+ puts "FYI: process : #{index + 1} of #{files.size}"
72
73
  dirname = File.dirname(File.expand_path(file))
73
74
  filename = File.basename(file)
74
75
  sanitized_name = FilenameCleaner::sanitize_filename(filename, options[:sep_char])
@@ -77,7 +78,8 @@ Options:
77
78
 
78
79
  if !options[:dry_run]
79
80
  if new_name != old_name
80
- puts "FYI: rename #{old_name} -> #{new_name}"
81
+ puts "FYI: old name: #{old_name}"
82
+ puts "FYI: new name: #{new_name}"
81
83
  FileUtils.mv old_name, new_name
82
84
  else
83
85
  puts "FYI: same file #{old_name}"
@@ -5,9 +5,8 @@ module FilenameCleaner
5
5
  #
6
6
  # @param [String] filename the input filename with extension
7
7
  # @retyrn [String] the output file with special characters replaced.
8
- def sanitize_filename(filename, sep_char = nil)
8
+ def sanitize_filename(filename, sep_char = '.')
9
9
  extension = File.extname(filename)
10
-
11
10
  if extension.empty?
12
11
  replace_dot!(sanitize(filename), sep_char)
13
12
  else
@@ -34,6 +33,9 @@ module FilenameCleaner
34
33
  # replace multiple occurrence of dot with one dot
35
34
  filename.gsub!(/#{Regexp.quote(DOT)}+/, DOT)
36
35
 
36
+ # remove the last char if it is a dot
37
+ filename.gsub!(/\.$/, '') if filename[-1] == DOT
38
+
37
39
  filename
38
40
  end
39
41
 
@@ -1,3 +1,3 @@
1
1
  module FilenameCleaner
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -8,11 +8,16 @@ describe FilenameCleaner do
8
8
  it 'works with text with extension' do
9
9
  FilenameCleaner.sanitize('filename.txt').must_equal 'filename.txt'
10
10
  end
11
+ it 'strips the end of string if not letters or numbers' do
12
+ FilenameCleaner.sanitize('filename .txt').must_equal 'filename.txt'
13
+ FilenameCleaner.sanitize('filename .txt').must_equal 'filename.txt'
14
+ FilenameCleaner.sanitize('filename !.txt').must_equal 'filename.txt'
15
+ end
11
16
  end
12
17
  context '#sanitize_filename' do
13
18
  describe 'file with extension' do
14
19
  it 'replaces mutilple consecutive chars with one' do
15
- FilenameCleaner.sanitize_filename('some!!!$file$:%.txt').must_equal 'some.file..txt'
20
+ FilenameCleaner.sanitize_filename('some!!!$file$:%.txt').must_equal 'some.file.txt'
16
21
  end
17
22
  it 'works with default separator' do
18
23
  FilenameCleaner.sanitize_filename('some file.txt').must_equal 'some.file.txt'
@@ -23,7 +28,7 @@ describe FilenameCleaner do
23
28
  end
24
29
  describe 'file without extension' do
25
30
  it 'replaces mutilple consecutive chars with one' do
26
- FilenameCleaner.sanitize_filename('some!!!$file$:%.').must_equal 'some.file.'
31
+ FilenameCleaner.sanitize_filename('some!!!$file$:%.').must_equal 'some.file'
27
32
  end
28
33
  context 'using default separator' do
29
34
  it 'works with simple input' do
@@ -41,6 +46,13 @@ describe FilenameCleaner do
41
46
  FilenameCleaner.sanitize_filename('File$without!extension', '-').must_equal 'File-without-extension'
42
47
  end
43
48
  end
49
+ context 'end of the filename' do
50
+ it 'strips the end of string if not letters or numbers' do
51
+ FilenameCleaner.sanitize_filename('filename .txt').must_equal 'filename.txt'
52
+ FilenameCleaner.sanitize_filename('filename .txt').must_equal 'filename.txt'
53
+ FilenameCleaner.sanitize_filename('filename !.txt').must_equal 'filename.txt'
54
+ end
55
+ end
44
56
  end
45
57
  end
46
58
  end
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.1.0
4
+ version: 0.1.1
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-12 00:00:00.000000000 Z
11
+ date: 2014-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -205,6 +205,7 @@ files:
205
205
  - ".rubocop.yml"
206
206
  - ".ruby-version"
207
207
  - ".yardopts"
208
+ - CHANGELOGS.md
208
209
  - Gemfile
209
210
  - Guardfile
210
211
  - LICENSE.txt