renamr 1.0.15 → 1.0.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b39e4e5a0e8eb0a2858888181609bcdddfdc71ab315de810bb7c23b6fb626ff0
4
- data.tar.gz: 40d581dd0b0351db79c896ced04446bf5cf5d2af0ec2ae186f044bb499b09cff
3
+ metadata.gz: 7bdc397de28bfad991bced9b577d5f69b510052389ed06af3044490fac938336
4
+ data.tar.gz: 56e4d20a103f4c330ba2ed9767d4ced07076b0eaf602a14a89ee3c25af7d0f26
5
5
  SHA512:
6
- metadata.gz: 03b888d15545d19a1e7ad552ebf416d51cf0d0c8dd3c11a547e2b07d467aa733bc64b888340aa7886136d1eadae811b2210db973f38e6c6f4301756c22daa83d
7
- data.tar.gz: ad1d1388214aa414ee34fa7f73823f82ff240d31695453fb920f09a218aa8c144754b38f669c7b4f06f43735719e8b1433cb32447d5994a1528847abb01a4e34
6
+ metadata.gz: 91bd8b832ccd58c174d91825a2690641ec21b8b408ab9da3ee16c3625530748373520aa5417d16ca707bcdf8a7f552cfdfd8e19c1e843d44f0492a8be155d761
7
+ data.tar.gz: 3f2e603f6ae91a1d3963fb0386c9c9b8f50c8fd12e109b675e6375aa70fd407440ca0df56c17bc3c347b074a94fe455c0445fb4fdbcda10d30600a3f142bd8d5
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2020-2025 David Rabkin
1
+ Copyright 2020-2026 David Rabkin
2
2
 
3
3
  Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
4
4
 
data/README.adoc CHANGED
@@ -8,7 +8,6 @@
8
8
  :img-rake: https://github.com/rdavid/renamr/actions/workflows/rake.yml/badge.svg
9
9
  :img-rubocop: https://github.com/rdavid/renamr/actions/workflows/rubocop.yml/badge.svg
10
10
  :img-style: https://img.shields.io/badge/code_style-rubocop-brightgreen.svg
11
- :img-test: https://github.com/rdavid/renamr/actions/workflows/test.yml/badge.svg
12
11
  :url-cv: http://cv.rabkin.co.il
13
12
  :url-gem: https://badge.fury.io/rb/renamr
14
13
  :url-hoc: https://hitsofcode.com/view/github/rdavid/renamr?branch=master
@@ -18,7 +17,6 @@
18
17
  :url-rubocop: https://github.com/rdavid/renamr/actions/workflows/rubocop.yml
19
18
  :url-ruby: https://www.ruby-lang.org/en/documentation/installation
20
19
  :url-style: https://github.com/rubocop/rubocop
21
- :url-test: https://github.com/rdavid/renamr/actions/workflows/test.yml
22
20
  :url-vale: https://vale.sh
23
21
  :url-yamllint: https://github.com/adrienverge/yamllint
24
22
 
@@ -28,7 +26,6 @@ image:{img-rake}[rake,link={url-rake}]
28
26
  image:{img-rubocop}[rubocop,link={url-rubocop}]
29
27
  image:{img-gem}[gem version,link={url-gem}]
30
28
  image:{img-style}[code style,link={url-style}]
31
- image:{img-test}[test,link={url-test}]
32
29
  image:{img-hoc}[hits of code,link={url-hoc}]
33
30
  image:{img-license}[license,link={url-license}]
34
31
 
@@ -36,16 +33,17 @@ toc::[]
36
33
 
37
34
  == About
38
35
 
39
- `renamr` organizes file and directory names.
36
+ `renamr` normalizes file and directory names.
37
+ It rewrites them with lowercase English letters, digits, and hyphens in place
38
+ of spaces and other symbols.
40
39
 
41
40
  == Installation
42
- The tool is designed to operate on macOS, GNU/Linux, Windows, and Unix-like
43
- operating systems.
44
- It is packaged as a Gem and requires Ruby version 3.2 or later.
45
- If you do not have the appropriate version on your platform, refer to
46
- {url-ruby}[Installing Ruby].
41
+ The tool runs on macOS, GNU/Linux, and other Unix-like operating systems, as
42
+ well as Windows.
43
+ It is packaged as a Ruby gem and requires Ruby 3.2 or later.
44
+ If your platform lacks a suitable Ruby, see {url-ruby}[Installing Ruby].
47
45
 
48
- Utilize this command for installing the package:
46
+ Install the gem with:
49
47
 
50
48
  [,sh]
51
49
  ----
@@ -54,7 +52,7 @@ gem install renamr
54
52
 
55
53
  == Updating
56
54
 
57
- Utilize this command for updating the package:
55
+ Update the gem with:
58
56
 
59
57
  [,sh]
60
58
  ----
@@ -66,17 +64,17 @@ gem update renamr
66
64
  [,sh]
67
65
  ----
68
66
  renamr [options]
69
- -a, --act Real renaming.
70
- -r, --rec Passes recursively.
71
- -l, --lim Limits name length.
72
- -m, --mod Prepends modification time.
73
- -d, --dir dir Directory to rename.
74
- -s, --src src A string to substitute.
75
- -t, --dst dst A string to replace to.
76
- -w, --wid wid Width of the table.
77
- -p, --pre str,beg A string to prepend to started from beg.
78
- -c, --cut pos,len Removes len symbols from pos.
79
- -v, --version Shows version.
67
+ -a, --act Performs actual renaming.
68
+ -c, --cut pos,len Removes len characters starting at pos.
69
+ -d, --dir dir Directory to process.
70
+ -l, --lim Limits file name length.
71
+ -m, --mod Prepends file modification time.
72
+ -p, --prepend str,beg Prepends a string.
73
+ -r, --rec Processes directories recursively.
74
+ -s, --src src String to replace.
75
+ -t, --dst dst Replacement string.
76
+ -v, --version Shows the version.
77
+ -w, --wid wid Output table width.
80
78
  ----
81
79
 
82
80
  == Example
@@ -86,9 +84,12 @@ renamr [options]
86
84
  renamr -d <source>
87
85
  ----
88
86
 
89
- It renames all files in `source` by default pattern: 26 English letters, 10 numbers, minus for spaces and other symbols.
87
+ This previews new names for all files in `source` using the default character
88
+ set: the 26 English letters, 10 digits, and hyphens in place of spaces and
89
+ other symbols.
90
+ Adding `-a` performs the actual renaming.
90
91
 
91
92
  == License
92
93
 
93
- `renamr` is copyright {url-cv}[David Rabkin] and available under a
94
+ `renamr` is copyright {url-cv}[David Rabkin] and is available under the
94
95
  {url-license}[Zero-Clause BSD license].
data/bin/renamr CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- # vi:ts=2 sw=2 tw=79 et lbr wrap
5
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
4
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
5
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
6
6
  # SPDX-License-Identifier: 0BSD
7
7
  #
8
- # This script renames files in given directory by specific rules.
8
+ # Renames files in a directory using configured rules.
9
9
 
10
10
  require_relative '../lib/renamr'
11
11
 
data/lib/renamr/action.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  module Renamr
8
- # An interface for actions implementation.
8
+ # Defines the interface for action implementations.
9
9
  class Action
10
10
  def do(src)
11
- raise "Undefined method Action.do is called with #{src}."
11
+ raise "Action.do must be overridden, called with #{src}."
12
12
  end
13
13
 
14
14
  def set(src) end
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require_relative 'action'
8
8
 
9
9
  module Renamr
10
- # Checks if the resulted string has only ASCII symbols.
10
+ # Checks whether the resulting string contains only ASCII characters.
11
11
  class ASCIIValidatorAction < Action
12
12
  def do(src)
13
13
  ascii = src.chars.select(&:ascii_only?).join
14
- raise "String #{src} has non-ASCII symbols." if src != ascii
14
+ raise "String #{src} contains non-ASCII characters." if src != ascii
15
15
 
16
16
  src
17
17
  end
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require 'i18n'
8
8
  require_relative 'action'
9
9
 
10
10
  module Renamr
11
- # Automatic localization.
11
+ # Performs automatic localization using I18n transliteration.
12
12
  class AutoLocalizationAction < Action
13
13
  def initialize
14
- super()
14
+ super
15
15
  I18n.config.available_locales = :en
16
16
  end
17
17
 
data/lib/renamr/char.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require_relative 'action'
8
8
 
9
9
  module Renamr
10
- # All special symbols besides some (., &, $) are replaced by minus.
10
+ # Replaces special symbols with hyphens, except `.`, `&`, and `$`.
11
11
  class CharAction < Action
12
12
  SYM = ' (){},~–\'![]_#@=„“”"`—+‘’;·‡«»%…'.chars.to_set.freeze
13
13
 
@@ -1,57 +1,66 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require 'optparse'
8
8
 
9
9
  module Renamr
10
- # Handles input parameters.
10
+ # Parses and validates command-line options.
11
11
  class Configurator
12
12
  DIC = [
13
- ['-a', '--act', 'Real renaming.', :act],
14
- ['-r', '--rec', 'Passes recursively.', :rec],
15
- ['-l', '--lim', 'Limits name length.', :lim],
16
- ['-m', '--mod', 'Prepends modification time.', :mod],
17
- ['-d', '--dir dir', 'Directory to rename.', :dir],
18
- ['-s', '--src src', 'A string to substitute.', :src],
19
- ['-t', '--dst dst', 'A string to replace to.', :dst],
20
- ['-w', '--wid wid', 'Width of the table.', :wid]
13
+ ['-a', '--act', 'Performs actual renaming.', :act],
14
+ ['-d', '--dir dir', 'Directory to process.', :dir],
15
+ ['-l', '--lim', 'Limits file name length.', :lim],
16
+ ['-m', '--mod', 'Prepends file modification time.', :mod],
17
+ ['-r', '--rec', 'Processes directories recursively.', :rec],
18
+ ['-s', '--src src', 'String to replace.', :src],
19
+ ['-t', '--dst dst', 'Replacement string.', :dst],
20
+ ['-w', '--wid wid', 'Output table width.', :wid]
21
21
  ].freeze
22
22
 
23
+ def add_simple(opt, key)
24
+ f, p, d = DIC.find { |_, _, _, k| k == key }
25
+ opt.on(f, p, d) { |i| @options[key] = i }
26
+ end
27
+
23
28
  def add_cut(opt)
24
- opt.on('-c', '--cut pos,len', Array, 'Removes symbols from pos.') do |l|
29
+ msg = 'Removes len characters starting at pos.'
30
+ opt.on('-c', '--cut pos,len', Array, msg) do |l|
25
31
  @options[:pos] = l[0]
26
32
  @options[:len] = l[1]
27
33
  end
28
34
  end
29
35
 
30
36
  def add_prepend(opt)
31
- opt.on('-p', '--prepend str,beg', Array, 'Prepend a string.') do |l|
37
+ opt.on('-p', '--prepend str,beg', Array, 'Prepends a string.') do |l|
32
38
  @options[:pre] = l[0]
33
39
  @options[:beg] = l[1].nil? ? 0 : l[1].to_i
34
40
  end
35
41
  end
36
42
 
37
43
  def add_version(opt)
38
- opt.on('-v', '--version', 'Show version.') do
44
+ opt.on('-v', '--version', 'Shows the version.') do
39
45
  puts "#{File.basename($PROGRAM_NAME)} #{VERSION} #{DATE}"
40
46
  exit
41
47
  end
42
48
  end
43
49
 
44
50
  def add(opt)
51
+ add_simple(opt, :act)
45
52
  add_cut(opt)
53
+ %i[dir lim mod].each { |k| add_simple(opt, k) }
46
54
  add_prepend(opt)
55
+ %i[rec src dst].each { |k| add_simple(opt, k) }
47
56
  add_version(opt)
57
+ add_simple(opt, :wid)
48
58
  end
49
59
 
50
60
  def initialize
51
61
  @options = {}
52
62
  OptionParser.new do |o|
53
63
  o.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options]."
54
- DIC.each { |f, p, d, k| o.on(f, p, d) { |i| @options[k] = i } }
55
64
  add(o)
56
65
  end.parse!
57
66
  validate
@@ -65,7 +74,7 @@ module Renamr
65
74
 
66
75
  @options[:dir] = File.expand_path(dir)
67
76
  end
68
- raise "Width of the table should exceeds 14 symbols: #{wid}." if wid < 15
77
+ raise "Table width must be at least 15 characters: #{wid}." if wid < 15
69
78
  end
70
79
 
71
80
  def act?
@@ -114,7 +123,8 @@ module Renamr
114
123
 
115
124
  def wid
116
125
  if @options[:wid].nil?
117
- # Reads current terminal width.
126
+
127
+ # Reads the current terminal width.
118
128
  wid = `tput cols`
119
129
  wid.to_s.empty? ? 79 : wid.to_i
120
130
  else
data/lib/renamr/date.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require 'date'
8
8
  require_relative 'action'
9
9
 
10
10
  module Renamr
11
- # Replaces any valid date, e.g. 2020-11-02 or 02-11-2020 with 20201102.
11
+ # Replaces valid dates (for example, 2020-11-02 or 02-11-2020) with 20201102.
12
12
  class DateAction < Action
13
13
  REG = /(\d+)-(\d+)-(\d+)/
14
14
  PAT = ['%m-%d-%Y', '%d-%m-%Y', '%Y-%m-%d', '%Y-%d-%m'].freeze
@@ -25,7 +25,7 @@ module Renamr
25
25
  PAT.each do |pat|
26
26
  return Date.strptime(sub, pat)
27
27
  rescue ArgumentError
28
- # Nothing to do.
28
+ # Tries the next date pattern.
29
29
  end
30
30
  nil
31
31
  end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require_relative 'action'
8
8
 
9
9
  module Renamr
10
- # All names should be downcased.
10
+ # Converts names to lowercase.
11
11
  class DowncaseAction < Action
12
12
  def do(src)
13
13
  src.downcase
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require_relative 'ascii_validator'
@@ -21,15 +21,15 @@ require_relative 'trim'
21
21
  require_relative 'truncate'
22
22
 
23
23
  module Renamr
24
- # Produces actions for certain directories.
24
+ # Builds an action pipeline for a directory.
25
25
  class ActionsFactory
26
- LIMIT = 143 # Synology eCryptfs limitation.
26
+ LIMIT = 143 # Matches the Synology eCryptfs limitation.
27
27
 
28
28
  def initialize(cfg)
29
29
  @cfg = cfg
30
30
  end
31
31
 
32
- def produce(dir) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
32
+ def produce(dir) # rubocop:disable Metrics/AbcSize
33
33
  if @cfg.lim?
34
34
  [
35
35
  OmitAction.new(LIMIT),
@@ -37,7 +37,7 @@ module Renamr
37
37
  ]
38
38
  else
39
39
  [
40
- PointAction.new(dir), # Should be the first.
40
+ PointAction.new(dir), # Runs first.
41
41
  @cfg.pos.nil? ? nil : RemoveAction.new(@cfg.pos, @cfg.len),
42
42
  @cfg.src.nil? ? nil : SubstituteAction.new(@cfg.src, @cfg.dst),
43
43
  ManualLocalizationAction.new,
@@ -1,25 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require_relative 'action'
8
8
 
9
9
  module Renamr
10
- # Manual localization.
10
+ # Transliterates accented Latin characters to their ASCII equivalents.
11
11
  class ManualLocalizationAction < Action
12
- SRC = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđ'\
13
- 'ÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏ'\
14
- 'ìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅ'\
15
- 'ņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝ'\
16
- 'ŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝ'\
12
+ SRC = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđ' \
13
+ 'ÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏ' \
14
+ 'ìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅ' \
15
+ 'ņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝ' \
16
+ 'ŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝ' \
17
17
  'ýÿŶŷŸŹźŻżŽž'
18
- DST = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDd'\
19
- 'EEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIII'\
20
- 'iiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnN'\
21
- 'nNnnNnOOOOOOooooooOoOoOoRrRrRrSsSs'\
22
- 'SsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwY'\
18
+ DST = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDd' \
19
+ 'EEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIII' \
20
+ 'iiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnN' \
21
+ 'nNnnNnOOOOOOooooooOoOoOoRrRrRrSsSs' \
22
+ 'SsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwY' \
23
23
  'yyYyYZzZzZz'
24
24
 
25
25
  def do(src)
data/lib/renamr/omit.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require_relative 'action'
8
8
 
9
9
  module Renamr
10
- # Omits file names shorter than limit.
10
+ # Skips file names shorter than the limit.
11
11
  class OmitAction < Action
12
12
  def initialize(lim)
13
13
  super()
data/lib/renamr/point.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require_relative 'action'
8
8
 
9
9
  module Renamr
10
- # All points besides extension are replaced by minus.
10
+ # Replaces dots with hyphens, except for the file extension separator.
11
11
  class PointAction < Action
12
12
  def initialize(dir)
13
13
  super()
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require_relative 'action'
8
8
 
9
9
  module Renamr
10
- # Prepends user patter.
10
+ # Inserts a user-provided string at the given position.
11
11
  class PrependAction < Action
12
12
  def initialize(beg, pre) # rubocop:disable Lint/MissingSuper
13
13
  raise 'beg cannot be nil.' if beg.nil?
14
- raise 'ins cannot be nil.' if pre.nil?
14
+ raise 'pre cannot be nil.' if pre.nil?
15
15
 
16
16
  @beg = beg
17
17
  @pre = pre
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require_relative 'action'
8
8
 
9
9
  module Renamr
10
- # Prepends file modification datestamp.
10
+ # Prepends the file modification date.
11
11
  class PrependDateAction < Action
12
12
  def initialize(dir)
13
13
  super()
data/lib/renamr/remove.rb CHANGED
@@ -1,28 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require_relative 'action'
8
8
 
9
9
  module Renamr
10
- # Removes symbols between left and right positions.
10
+ # Removes a substring by 1-based position and length.
11
11
  class RemoveAction < Action
12
12
  def initialize(pos, len)
13
13
  super()
14
- raise 'len cannot bi nil.' if len.nil?
14
+ raise 'len cannot be nil.' if len.nil?
15
+ raise 'len must be positive.' unless len.to_i.positive?
15
16
  raise 'pos cannot be nil.' if pos.nil?
16
- raise 'pos has to be positive.' unless pos.to_i.positive?
17
+ raise 'pos must be positive.' unless pos.to_i.positive?
17
18
 
18
19
  @pos = pos.to_i
19
20
  @len = len.to_i
20
21
  end
21
22
 
22
23
  def do(src)
23
- return src[@len..] if @pos == 1
24
-
25
- src[0..@pos - 1] + src[@pos + @len..]
24
+ src[0...(@pos - 1)] + (src[(@pos - 1 + @len)..] || '')
26
25
  end
27
26
  end
28
27
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require 'fileutils'
@@ -10,7 +10,7 @@ require_relative 'factory'
10
10
  require_relative 'reporter'
11
11
 
12
12
  module Renamr
13
- # Renames file by certain rules.
13
+ # Renames files using configured rules.
14
14
  class Renamer
15
15
  def initialize
16
16
  @cfg = Configurator.new
@@ -29,20 +29,21 @@ module Renamr
29
29
  rep.add(File.basename(src), File.basename(dst))
30
30
  rescue StandardError => e
31
31
  rep.add(File.basename(src), e)
32
- puts e.backtrace.join("\n\t")
33
- .sub("\n\t", ": #{e}#{e.class ? " (#{e.class})" : ''}\n\t")
32
+ msg = ": #{e}"
33
+ msg += " (#{e.class})" if e.class
34
+ msg += "\n\t#{e.backtrace.join("\n\t")}"
35
+ puts msg
34
36
  end
35
37
  end
36
38
  rep.do
37
39
  end
38
40
 
39
41
  def unique(dat, nme)
40
- dst = []
41
- dat.each { |_, d| dst << File.basename(d) } # rubocop:disable Style/HashEachMethods
42
+ dst = dat.map { |_, d| File.basename(d) }
42
43
  return nme unless dst.include?(nme)
43
44
 
44
45
  ext = File.extname(nme)
45
- 0.step do |i| # Infinitive loop with index.
46
+ 0.step do |i| # Iterates indefinitely with an index.
46
47
  n = ext.nil? ? "#{nme}-#{i}" : "#{File.basename(nme, ext)}-#{i}#{ext}"
47
48
  return n unless dst.include?(n)
48
49
  end
@@ -53,7 +54,8 @@ module Renamr
53
54
 
54
55
  dat = []
55
56
  act = @fac.produce(dir)
56
- # Doesn't include hidden files.
57
+
58
+ # Skips hidden files.
57
59
  Dir.entries(dir).reject { |f| f.start_with?('.') }.sort.each do |nme|
58
60
  src = File.join(dir, nme)
59
61
  do_dir(src) if @cfg.rec? && File.directory?(src)
@@ -1,15 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require 'terminal-table'
8
8
  require_relative 'action'
9
+ require_relative 'timer'
9
10
  require_relative 'utils'
10
11
 
11
12
  module Renamr
12
- # Formats and prints output data.
13
+ # Formats and prints rename results.
13
14
  # rubocop:disable Style/ClassVars
14
15
  class Reporter
15
16
  @@tim = Timer.new
data/lib/renamr/rutoen.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # vi:ts=2 sw=2 tw=79 et lbr wrap
4
- # SPDX-FileCopyrightText: 2018-2025 David Rabkin
3
+ # vi: et lbr sw=2 ts=2 tw=79 wrap
4
+ # SPDX-FileCopyrightText: 2018-2026 David Rabkin
5
5
  # SPDX-License-Identifier: 0BSD
6
6
 
7
7
  require_relative 'action'