renamr 1.0.9 → 1.0.10
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 +4 -4
- data/lib/renamr/factory.rb +1 -3
- data/lib/renamr/renamer.rb +18 -4
- data/lib/renamr/version.rb +2 -2
- data/renamr-1.0.9.gem +0 -0
- metadata +6 -6
- data/lib/renamr/existence.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdddf30ae00e41f680036bee50f3e1c34da6ae3b569aeec8c40f136621a1ce88
|
4
|
+
data.tar.gz: 83724725b200aac5218a4ab319c769b6b982b25398ab5820ef4532b2d09b56b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e055a5b53a6fe4d9ac68be46cb207f47b6de392a3ef77d59cb95f5e5fca834f8f85d6fb327fae7f962811271c4a5b9ac8c8a1e92212b73e51afc1edffd956235
|
7
|
+
data.tar.gz: f9e7464fdfed6a0a31a15e03b1bddc54e086693806ae629aee80aff9d1d1b83566e0a87fb12beed599c56fc8193aae7f3df95a2ee36ebb7de7c83ed1e58bda17
|
data/lib/renamr/factory.rb
CHANGED
@@ -8,7 +8,6 @@ require_relative 'auto_localization'
|
|
8
8
|
require_relative 'char'
|
9
9
|
require_relative 'date'
|
10
10
|
require_relative 'downcase'
|
11
|
-
require_relative 'existence'
|
12
11
|
require_relative 'manual_localization'
|
13
12
|
require_relative 'omit'
|
14
13
|
require_relative 'point'
|
@@ -50,8 +49,7 @@ module Renamr
|
|
50
49
|
ASCIIValidatorAction.new,
|
51
50
|
TrimAction.new,
|
52
51
|
TruncateAction.new(LIMIT),
|
53
|
-
DateAction.new
|
54
|
-
ExistenceAction.new(dir, LIMIT) # Should be the last.
|
52
|
+
DateAction.new
|
55
53
|
].compact
|
56
54
|
end
|
57
55
|
end
|
data/lib/renamr/renamer.rb
CHANGED
@@ -24,7 +24,7 @@ module Renamr
|
|
24
24
|
next
|
25
25
|
end
|
26
26
|
begin
|
27
|
-
|
27
|
+
File.rename(src, dst) if @cfg.act?
|
28
28
|
rep.add(File.basename(src), File.basename(dst))
|
29
29
|
rescue StandardError => e
|
30
30
|
rep.add(File.basename(src), e)
|
@@ -35,6 +35,18 @@ module Renamr
|
|
35
35
|
rep.do
|
36
36
|
end
|
37
37
|
|
38
|
+
def unique(dat, nme)
|
39
|
+
dst = []
|
40
|
+
dat.each { |_, d| dst << File.basename(d) }
|
41
|
+
return nme unless dst.include?(nme)
|
42
|
+
|
43
|
+
ext = File.extname(nme)
|
44
|
+
0.step do |i| # Infinitive loop with index.
|
45
|
+
n = ext.nil? ? "#{nme}-#{i}" : "#{File.basename(nme, ext)}-#{i}#{ext}"
|
46
|
+
return n unless dst.include?(n)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
38
50
|
def do_dir(dir) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
|
39
51
|
raise "No such directory: #{dir}." unless File.directory?(dir)
|
40
52
|
|
@@ -42,12 +54,14 @@ module Renamr
|
|
42
54
|
act = @fac.produce(dir)
|
43
55
|
# Doesn't include hidden files.
|
44
56
|
Dir.entries(dir).reject { |f| f.start_with?('.') }.sort.each do |nme|
|
45
|
-
p nme
|
46
57
|
src = File.join(dir, nme)
|
47
58
|
do_dir(src) if @cfg.rec? && File.directory?(src)
|
48
59
|
act.each { |a| a.set(nme) }
|
49
|
-
act.each { |a| break if (nme = a.do(nme)).nil? }
|
50
|
-
|
60
|
+
act.each { |a| break if (nme = a.do(nme)).nil? } # rubocop:disable Style/CombinableLoops
|
61
|
+
next if nme.nil?
|
62
|
+
|
63
|
+
nme = unique(dat, nme)
|
64
|
+
dat << [src, File.join(dir, nme)]
|
51
65
|
end
|
52
66
|
move(dir, dat) if dat.any?
|
53
67
|
end
|
data/lib/renamr/version.rb
CHANGED
data/renamr-1.0.9.gem
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: renamr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Rabkin
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: date
|
@@ -145,7 +145,6 @@ files:
|
|
145
145
|
- lib/renamr/configurator.rb
|
146
146
|
- lib/renamr/date.rb
|
147
147
|
- lib/renamr/downcase.rb
|
148
|
-
- lib/renamr/existence.rb
|
149
148
|
- lib/renamr/factory.rb
|
150
149
|
- lib/renamr/manual_localization.rb
|
151
150
|
- lib/renamr/omit.rb
|
@@ -164,12 +163,13 @@ files:
|
|
164
163
|
- renamr-1.0.6.gem
|
165
164
|
- renamr-1.0.7.gem
|
166
165
|
- renamr-1.0.8.gem
|
166
|
+
- renamr-1.0.9.gem
|
167
167
|
- renamr.gemspec
|
168
168
|
homepage: https://github.com/rdavid/renamr
|
169
169
|
licenses:
|
170
170
|
- 0BSD
|
171
171
|
metadata: {}
|
172
|
-
post_install_message:
|
172
|
+
post_install_message:
|
173
173
|
rdoc_options: []
|
174
174
|
require_paths:
|
175
175
|
- lib
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
187
|
rubygems_version: 3.1.4
|
188
|
-
signing_key:
|
188
|
+
signing_key:
|
189
189
|
specification_version: 4
|
190
190
|
summary: File and directory names organiser.
|
191
191
|
test_files: []
|
data/lib/renamr/existence.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# vi:ts=2 sw=2 tw=79 et lbr wrap
|
4
|
-
# Copyright 2018 by David Rabkin
|
5
|
-
|
6
|
-
require_relative 'action'
|
7
|
-
|
8
|
-
module Renamr
|
9
|
-
# Adds number from 0 to 9 in case of file existence.
|
10
|
-
class ExistenceAction < Action
|
11
|
-
ITERATION = 10
|
12
|
-
|
13
|
-
def initialize(dir, lim)
|
14
|
-
raise 'dir cannot be nil.' if dir.nil?
|
15
|
-
raise 'lim cannot be nil.' if lim.nil?
|
16
|
-
|
17
|
-
@dir = dir
|
18
|
-
@lim = lim
|
19
|
-
end
|
20
|
-
|
21
|
-
def do(src) # rubocop:disable MethodLength, CyclomaticComplexity, AbcSize
|
22
|
-
raise 'ExistenceAction needs original file name.' if @src.nil?
|
23
|
-
return src if src == @src
|
24
|
-
return src unless File.exist?(File.join(@dir, src))
|
25
|
-
|
26
|
-
if src.length == @lim
|
27
|
-
ext = File.extname(src)
|
28
|
-
src = src[0..@lim - ext.length - ITERATION.to_s.length + 1]
|
29
|
-
src << ext
|
30
|
-
end
|
31
|
-
nme = File.basename(src, '.*')
|
32
|
-
nme = '' if nme.length == 1
|
33
|
-
ext = File.extname(src)
|
34
|
-
(0..ITERATION).each do |i|
|
35
|
-
n = File.join(@dir, nme + i.to_s + ext)
|
36
|
-
return n unless File.exist?(n)
|
37
|
-
end
|
38
|
-
raise "Unable to compose a new name: #{src}."
|
39
|
-
end
|
40
|
-
|
41
|
-
def set(src)
|
42
|
-
@src = src
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|