filter_rename 1.1.0 → 1.2.0

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.
@@ -1,135 +1,184 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FilterRename
4
-
5
4
  module Filters
6
-
7
5
  class Select < FilterBase
8
- def self.hint; 'Select the target where apply further transformations'; end
9
- def self.params; 'name|ext|folder|...'; end
6
+ def self.hint
7
+ "Select the target where apply further transformations"
8
+ end
9
+
10
+ def self.params
11
+ "name|ext|folder|..."
12
+ end
10
13
 
11
14
  def filter(params)
12
- raise InvalidTarget, params[0] unless has_target? params[0].to_sym
15
+ raise InvalidTarget, params[0] unless target? params[0].to_sym
16
+
13
17
  set_config :target, params[0].to_sym
14
18
  end
15
19
  end
16
20
 
17
21
  class Config < FilterBase
18
- def self.hint; 'Set config PARAM to VALUE'; end
19
- def self.params; 'PARAM:VALUE[,PARAMS2:VALUE2,...]'; end
22
+ def self.hint
23
+ "Set config PARAM to VALUE"
24
+ end
25
+
26
+ def self.params
27
+ "PARAM:VALUE[,PARAMS2:VALUE2,...]"
28
+ end
20
29
 
21
30
  def filter(params)
22
31
  params.each do |par|
23
- set_config(par.split(':')[0], par.split(':')[1])
32
+ set_config(par.split(":")[0], par.split(":")[1])
24
33
  end
25
34
  end
26
35
  end
27
36
 
28
37
  #------------------------
29
38
 
30
-
31
39
  class AddNumber < FilterNumber
32
- def self.hint; 'Add NUM to the NTH number'; end
33
- def self.params; 'NTH,NUM'; end
40
+ def self.hint
41
+ "Add NUM to the NTH number"
42
+ end
34
43
 
35
- def filtered_number(num, param_num)
44
+ def self.params
45
+ "NTH,NUM"
46
+ end
47
+
48
+ def filtered_number(num, _param_num)
36
49
  num.to_i + params[1].to_i
37
50
  end
38
51
  end
39
52
 
40
-
41
53
  class AddNumberFrom < FilterNumber
42
- def self.hint; 'Add the number from TARGET to the NTH'; end
43
- def self.params; 'NTH;TARGET'; end
54
+ def self.hint
55
+ "Add the number from TARGET to the NTH"
56
+ end
44
57
 
45
- def filtered_number(num, param_num)
58
+ def self.params
59
+ "NTH,TARGET"
60
+ end
61
+
62
+ def filtered_number(num, _param_num)
46
63
  num.to_i + get_string(params[1]).to_i
47
64
  end
48
65
  end
49
66
 
50
-
51
67
  class Append < FilterBase
52
- def self.hint; 'Append the TEXT to the current target'; end
53
- def self.params; 'TEXT'; end
68
+ def self.hint
69
+ "Append the TEXT to the current target"
70
+ end
71
+
72
+ def self.params
73
+ "TEXT"
74
+ end
54
75
 
55
76
  def filter(params)
56
- super "#{get_string}#{params[0]}"
77
+ super("#{get_string}#{params[0]}")
57
78
  end
58
79
  end
59
80
 
60
-
61
81
  class AppendFrom < FilterBase
62
- def self.hint; 'Append the text from TARGET'; end
63
- def self.params; 'TARGET'; end
82
+ def self.hint
83
+ "Append the text from TARGET"
84
+ end
85
+
86
+ def self.params
87
+ "TARGET"
88
+ end
64
89
 
65
90
  def filter(params)
66
- super "#{get_string}#{get_string(params[0])}"
91
+ super("#{get_string}#{get_string(params[0])}")
67
92
  end
68
93
  end
69
94
 
70
-
71
95
  class AppendAsWordTo < FilterBase
72
- def self.hint; 'Append the TEXT to TARGET as a word'; end
73
- def self.params; 'TEXT,TARGET'; end
96
+ def self.hint
97
+ "Append the TEXT to TARGET as a word"
98
+ end
99
+
100
+ def self.params
101
+ "TEXT,TARGET"
102
+ end
74
103
 
75
104
  def filter(params)
76
105
  ws = get_config(:word_separator)
77
106
  set_string(get_string(params[1]).to_s.split(ws).push(params[0]).join(ws), params[1])
78
- super get_string
107
+ super(get_string)
79
108
  end
80
109
  end
81
110
 
82
-
83
111
  class AppendTo < FilterBase
84
- def self.hint; 'Append the TEXT to TARGET'; end
85
- def self.params; 'TEXT,TARGET'; end
112
+ def self.hint
113
+ "Append the TEXT to TARGET"
114
+ end
115
+
116
+ def self.params
117
+ "TEXT,TARGET"
118
+ end
86
119
 
87
120
  def filter(params)
88
121
  set_string(get_string(params[1]).to_s + params[0], params[1])
89
- super get_string
122
+ super(get_string)
90
123
  end
91
124
  end
92
125
 
93
-
94
126
  class AppendNumberTo < FilterNumber
95
- def self.hint; 'Append the NTH number to TARGET'; end
96
- def self.params; 'NTH,TARGET'; end
127
+ def self.hint
128
+ "Append the NTH number to TARGET"
129
+ end
130
+
131
+ def self.params
132
+ "NTH,TARGET"
133
+ end
97
134
 
98
135
  def self_targeted?
99
136
  params[-1] == current_target
100
137
  end
101
138
 
102
- def filtered_number(num, param_num)
139
+ def filtered_number(num, _param_num)
103
140
  str = get_string(params[1])
104
141
  set_string("#{str}#{num}", params[1])
105
142
  num
106
143
  end
107
144
  end
108
145
 
109
-
110
146
  class AppendToNumber < FilterNumber
111
- def self.hint; 'Append the TEXT to the NTH number'; end
112
- def self.params; 'NTH,TEXT'; end
147
+ def self.hint
148
+ "Append the TEXT to the NTH number"
149
+ end
113
150
 
114
- def filtered_number(num, param_num)
151
+ def self.params
152
+ "NTH,TEXT"
153
+ end
154
+
155
+ def filtered_number(num, _param_num)
115
156
  "#{num}#{params[1]}"
116
157
  end
117
158
  end
118
159
 
119
-
120
160
  class AppendToWord < FilterWord
121
- def self.hint; 'Append the TEXT to the NTH word'; end
122
- def self.params; 'NTH,TEXT'; end
161
+ def self.hint
162
+ "Append the TEXT to the NTH word"
163
+ end
123
164
 
124
- def filtered_word(word, param_num)
165
+ def self.params
166
+ "NTH,TEXT"
167
+ end
168
+
169
+ def filtered_word(word, _param_num)
125
170
  word + params[1]
126
171
  end
127
172
  end
128
173
 
129
-
130
174
  class AppendWordFrom < FilterWord
131
- def self.hint; 'Append the NTH word from TARGET'; end
132
- def self.params; 'NTH,TARGET'; end
175
+ def self.hint
176
+ "Append the NTH word from TARGET"
177
+ end
178
+
179
+ def self.params
180
+ "NTH,TARGET"
181
+ end
133
182
 
134
183
  def string_to_loop
135
184
  get_string(params[1])
@@ -139,92 +188,120 @@ module FilterRename
139
188
  true
140
189
  end
141
190
 
142
- def filtered_word(word, param_num)
191
+ def filtered_word(word, _param_num)
143
192
  set_string([get_string, word].join(ws))
144
193
  word
145
194
  end
146
195
  end
147
196
 
148
-
149
197
  class AppendWordTo < FilterWord
150
- def self.hint; 'Append the NTH word to TARGET'; end
151
- def self.params; 'NTH,TARGET'; end
198
+ def self.hint
199
+ "Append the NTH word to TARGET"
200
+ end
201
+
202
+ def self.params
203
+ "NTH,TARGET"
204
+ end
152
205
 
153
206
  def self_targeted?
154
207
  params[-1] == current_target
155
208
  end
156
209
 
157
- def filtered_word(word, param_num)
210
+ def filtered_word(word, _param_num)
158
211
  set_string([get_string(params[1]), word].join(ws), params[1])
159
212
  word
160
213
  end
161
214
  end
162
215
 
163
-
164
216
  class Capitalize < FilterBase
165
- def self.hint; 'Capitalize each word'; end
166
- def self.params; nil; end
217
+ def self.hint
218
+ "Capitalize each word"
219
+ end
167
220
 
168
- def filter(params)
221
+ def self.params
222
+ nil
223
+ end
224
+
225
+ def filter(_params)
169
226
  ws = get_config(:word_separator)
170
- super (get_string.split(ws).map(&:capitalize)).join(ws)
227
+ super(get_string.split(ws).map(&:capitalize).join(ws))
171
228
  end
172
229
  end
173
230
 
174
-
175
231
  class CapitalizeWord < FilterWord
176
- def self.hint; 'Capitalize the NTH word'; end
177
- def self.params; 'NTH'; end
232
+ def self.hint
233
+ "Capitalize the NTH word"
234
+ end
178
235
 
179
- def filtered_word(word, param_num)
236
+ def self.params
237
+ "NTH"
238
+ end
239
+
240
+ def filtered_word(word, _param_num)
180
241
  word.capitalize
181
242
  end
182
243
  end
183
244
 
184
-
185
245
  class CopyFrom < FilterBase
186
- def self.hint; 'Copy the text from TARGET'; end
187
- def self.params; 'TARGET'; end
246
+ def self.hint
247
+ "Copy the text from TARGET"
248
+ end
249
+
250
+ def self.params
251
+ "TARGET"
252
+ end
188
253
 
189
254
  def filter(params)
190
- super get_string(params[0]).to_s
255
+ super(get_string(params[0]).to_s)
191
256
  end
192
257
  end
193
258
 
194
-
195
259
  class CopyNumberTo < FilterNumber
196
- def self.hint; 'Copy the NTH number to TARGET'; end
197
- def self.params; 'NTH,TARGET'; end
260
+ def self.hint
261
+ "Copy the NTH number to TARGET"
262
+ end
263
+
264
+ def self.params
265
+ "NTH,TARGET"
266
+ end
198
267
 
199
268
  def self_targeted?
200
269
  params[-1] == current_target
201
270
  end
202
271
 
203
- def filtered_number(num, param_num)
272
+ def filtered_number(num, _param_num)
204
273
  set_string(num, params[1])
205
274
  num
206
275
  end
207
276
  end
208
277
 
209
-
210
278
  class CopyOccurrenceTo < FilterOccurrence
211
- def self.hint; 'Copy the NTH occurrence of REGEX to TARGET'; end
212
- def self.params; 'NTH,REGEX,TARGET'; end
279
+ def self.hint
280
+ "Copy the NTH occurrence of REGEX to TARGET"
281
+ end
282
+
283
+ def self.params
284
+ "NTH,REGEX,TARGET"
285
+ end
213
286
 
214
287
  def self_targeted?
215
288
  params[-1] == current_target
216
289
  end
217
290
 
218
- def filtered_occurrence(occurrence, param_num)
291
+ def filtered_occurrence(occurrence, _param_num)
219
292
  set_string(occurrence, params[-1])
220
293
  occurrence
221
294
  end
222
295
  end
223
296
 
224
-
225
297
  class CopyTo < FilterRegExp
226
- def self.hint; 'Copy the text selected by REGEX to TARGET or TARGET_#'; end
227
- def self.params; 'REGEX,TARGET'; end
298
+ def self.hint
299
+ "Copy the text selected by REGEX to TARGET"
300
+ end
301
+
302
+ def self.params
303
+ "REGEX,TARGET"
304
+ end
228
305
 
229
306
  def filtered_regexp(matches, params)
230
307
  if matches.length > 2
@@ -236,19 +313,25 @@ module FilterRename
236
313
  end
237
314
  end
238
315
 
239
-
240
316
  class CopyWord < FilterWord
241
- def self.hint; 'Copy the NTH1 word to the NTH2 place'; end
242
- def self.params; 'NTH1,NTH2'; end
317
+ def self.hint
318
+ "Copy the NTH1 word to the NTH2 place"
319
+ end
243
320
 
244
- def indexed_params; 2; end
321
+ def self.params
322
+ "NTH1,NTH2"
323
+ end
324
+
325
+ def indexed_params
326
+ 2
327
+ end
245
328
 
246
329
  def filtered_word(word, param_num)
247
330
  case param_num
248
331
  when 1
249
332
  @word = word
250
333
  when params_expanded.length
251
- word = [@word, word].join(ws)
334
+ word = [word, @word].join(ws)
252
335
  else
253
336
  @word = [@word, word].join(ws)
254
337
  end
@@ -257,82 +340,116 @@ module FilterRename
257
340
  end
258
341
  end
259
342
 
260
-
261
343
  class Delete < FilterRegExp
262
- def self.hint; 'Remove the text matching REGEX'; end
263
- def self.params; 'REGEX'; end
344
+ def self.hint
345
+ "Remove the text matching REGEX"
346
+ end
264
347
 
265
- def filtered_regexp(matches, params)
266
- ''
348
+ def self.params
349
+ "REGEX"
267
350
  end
268
- end
269
351
 
352
+ def filtered_regexp(_matches, _params)
353
+ ""
354
+ end
355
+ end
270
356
 
271
357
  class DeleteNumber < FilterNumber
272
- def self.hint; 'Remove the NTH number'; end
273
- def self.params; 'NTH'; end
358
+ def self.hint
359
+ "Remove the NTH number"
360
+ end
274
361
 
275
- def filtered_number(num, param_num)
276
- ''
362
+ def self.params
363
+ "NTH"
277
364
  end
278
- end
279
365
 
366
+ def filtered_number(_num, _param_num)
367
+ ""
368
+ end
369
+ end
280
370
 
281
371
  class DeleteOccurrence < FilterOccurrence
282
- def self.hint; 'Delete the NTH occurrence of REGEXP'; end
283
- def self.params; 'NTH,REGEXP'; end
372
+ def self.hint
373
+ "Delete the NTH occurrence of REGEXP"
374
+ end
375
+
376
+ def self.params
377
+ "NTH,REGEXP"
378
+ end
284
379
 
285
- def filtered_occurrence(occurrence, param_num)
380
+ def filtered_occurrence(_occurrence, _param_num)
286
381
  nil
287
382
  end
288
383
  end
289
384
 
290
-
291
385
  class DeleteWord < FilterWord
292
- def self.hint; 'Remove the NTH word'; end
293
- def self.params; 'NTH'; end
386
+ def self.hint
387
+ "Remove the NTH word"
388
+ end
294
389
 
295
- def filtered_word(word, param_num)
390
+ def self.params
391
+ "NTH"
392
+ end
393
+
394
+ def filtered_word(_word, _param_num)
296
395
  nil
297
396
  end
298
397
  end
299
398
 
300
-
301
399
  class FormatNumber < FilterNumber
302
- def self.hint; 'Format the NTH number adding leading zeroes to have LENGTH'; end
303
- def self.params; 'NTH,LENGTH'; end
400
+ def self.hint
401
+ "Format the NTH number adding leading zeroes to have LENGTH"
402
+ end
304
403
 
305
- def filtered_number(num, param_num)
306
- num.to_i.to_s.rjust(params[1].to_i, '0')
404
+ def self.params
405
+ "NTH,LENGTH"
307
406
  end
308
- end
309
407
 
408
+ def filtered_number(num, _param_num)
409
+ num.to_i.to_s.rjust(params[1].to_i, "0")
410
+ end
411
+ end
310
412
 
311
413
  class InsertAfterWord < FilterWord
312
- def self.hint; 'Insert the WORD after the NTH word'; end
313
- def self.params; 'NTH,WORD'; end
414
+ def self.hint
415
+ "Insert the WORD after the NTH word"
416
+ end
314
417
 
315
- def filtered_word(word, param_num)
418
+ def self.params
419
+ "NTH,WORD"
420
+ end
421
+
422
+ def filtered_word(word, _param_num)
316
423
  [word, params[1]].join(ws)
317
424
  end
318
425
  end
319
426
 
320
-
321
427
  class InsertBeforeWord < FilterWord
322
- def self.hint; 'Insert the WORD after the NTH word'; end
323
- def self.params; 'NTH,WORD'; end
428
+ def self.hint
429
+ "Insert the WORD after the NTH word"
430
+ end
324
431
 
325
- def filtered_word(word, param_num)
432
+ def self.params
433
+ "NTH,WORD"
434
+ end
435
+
436
+ def filtered_word(word, _param_num)
326
437
  [params[1], word].join(ws)
327
438
  end
328
439
  end
329
440
 
330
-
331
441
  class JoinNumbers < FilterNumber
332
- def self.hint; 'Join the words NTH1 and NTH2 and replace the NTH3 number with it'; end
333
- def self.params; 'NTH1,NTH2,NTH3'; end
442
+ def self.hint
443
+ "Join the numbers NTH1 and NTH2 and replace the NTH3 number with it"
444
+ end
334
445
 
335
- def indexed_params; 3; end
446
+ def self.params
447
+ "NTH1,NTH2,NTH3"
448
+ end
449
+
450
+ def indexed_params
451
+ 3
452
+ end
336
453
 
337
454
  def filtered_number(number, param_num)
338
455
  case param_num
@@ -350,12 +467,18 @@ module FilterRename
350
467
  end
351
468
  end
352
469
 
353
-
354
470
  class JoinWords < FilterWord
355
- def self.hint; 'Join the words NTH1 and NTH2 and replace the NTH3 word with it'; end
356
- def self.params; 'NTH1,NTH2,NTH3'; end
471
+ def self.hint
472
+ "Join the words NTH1 and NTH2 and replace the NTH3 word with it"
473
+ end
357
474
 
358
- def indexed_params; 3; end
475
+ def self.params
476
+ "NTH1,NTH2,NTH3"
477
+ end
478
+
479
+ def indexed_params
480
+ 3
481
+ end
359
482
 
360
483
  def filtered_word(word, param_num)
361
484
  case param_num
@@ -373,40 +496,56 @@ module FilterRename
373
496
  end
374
497
  end
375
498
 
376
-
377
499
  class LeftJustify < FilterBase
378
- def self.hint; 'Add enough CHAR(s) to the right side to have a N-length string'; end
379
- def self.params; 'N,CHAR'; end
500
+ def self.hint
501
+ "Add enough CHAR(s) to the right side to have a N-length string"
502
+ end
503
+
504
+ def self.params
505
+ "N,CHAR"
506
+ end
380
507
 
381
508
  def filter(params)
382
- super get_string.ljust(params[0].to_i, params[1])
509
+ super(get_string.ljust(params[0].to_i, params[1]))
383
510
  end
384
511
  end
385
512
 
386
-
387
513
  class Lowercase < FilterBase
388
- def self.hint; 'Lowercase each word'; end
389
- def self.params; nil; end
514
+ def self.hint
515
+ "Lowercase each word"
516
+ end
390
517
 
391
- def filter(params)
392
- super get_string.downcase
518
+ def self.params
519
+ nil
393
520
  end
394
- end
395
521
 
522
+ def filter(_params)
523
+ super(get_string.downcase)
524
+ end
525
+ end
396
526
 
397
527
  class LowercaseWord < FilterWord
398
- def self.hint; 'Lowercase the NTH word'; end
399
- def self.params; 'NTH'; end
528
+ def self.hint
529
+ "Lowercase the NTH word"
530
+ end
400
531
 
401
- def filtered_word(word, param_num)
532
+ def self.params
533
+ "NTH"
534
+ end
535
+
536
+ def filtered_word(word, _param_num)
402
537
  word.downcase
403
538
  end
404
539
  end
405
540
 
406
-
407
541
  class MoveTo < FilterRegExp
408
- def self.hint; 'Move the text selected by REGEX to TARGET or TARGET_#'; end
409
- def self.params; 'REGEX,TARGET'; end
542
+ def self.hint
543
+ "Move the text selected by REGEX to TARGET"
544
+ end
545
+
546
+ def self.params
547
+ "REGEX,TARGET"
548
+ end
410
549
 
411
550
  def filtered_regexp(matches, params)
412
551
  if matches.length > 2
@@ -414,46 +553,60 @@ module FilterRename
414
553
  else
415
554
  set_string(matches[1], params[1])
416
555
  end
417
- ''
556
+ ""
418
557
  end
419
558
  end
420
559
 
421
-
422
560
  class MoveNumberTo < FilterNumber
423
- def self.hint; 'Move the NTH number to TARGET overwriting it'; end
424
- def self.params; 'NTH,TARGET'; end
561
+ def self.hint
562
+ "Move the NTH number to TARGET overwriting it"
563
+ end
564
+
565
+ def self.params
566
+ "NTH,TARGET"
567
+ end
425
568
 
426
569
  def self_targeted?
427
570
  params[-1] == current_target
428
571
  end
429
572
 
430
- def filtered_number(num, param_num)
573
+ def filtered_number(num, _param_num)
431
574
  set_string(num, params[1])
432
- ''
575
+ ""
433
576
  end
434
577
  end
435
578
 
436
-
437
579
  class MoveOccurrenceTo < FilterOccurrence
438
- def self.hint; 'Move the NTH occurrence of REGEX to TARGET overwriting it'; end
439
- def self.params; 'NTH,REGEX,TARGET'; end
580
+ def self.hint
581
+ "Move the NTH occurrence of REGEX to TARGET overwriting it"
582
+ end
583
+
584
+ def self.params
585
+ "NTH,REGEX,TARGET"
586
+ end
440
587
 
441
588
  def self_targeted?
442
589
  params[-1] == current_target
443
590
  end
444
591
 
445
- def filtered_occurrence(occurrence, param_num)
592
+ def filtered_occurrence(occurrence, _param_num)
446
593
  set_string(occurrence, params[-1])
447
594
  nil
448
595
  end
449
596
  end
450
597
 
451
-
452
598
  class MoveWord < FilterWord
453
- def self.hint; 'Move the NTH1 word to the NTH2 place'; end
454
- def self.params; 'NTH1,NTH2'; end
599
+ def self.hint
600
+ "Move the NTH1 word to the NTH2 place"
601
+ end
602
+
603
+ def self.params
604
+ "NTH1,NTH2"
605
+ end
455
606
 
456
- def indexed_params; 2; end
607
+ def indexed_params
608
+ 2
609
+ end
457
610
 
458
611
  def filtered_word(word, param_num)
459
612
  case param_num
@@ -471,75 +624,110 @@ module FilterRename
471
624
  end
472
625
  end
473
626
 
474
-
475
627
  class MoveWordTo < FilterWord
476
- def self.hint; 'Move the NTH word to TARGET overwriting it'; end
477
- def self.params; 'NTH,TARGET'; end
628
+ def self.hint
629
+ "Move the NTH word to TARGET overwriting it"
630
+ end
631
+
632
+ def self.params
633
+ "NTH,TARGET"
634
+ end
478
635
 
479
636
  def self_targeted?
480
637
  params[-1] == current_target
481
638
  end
482
639
 
483
640
  def filtered_word(word, param_num)
484
- set_string(word, params[1])
641
+ case param_num
642
+ when params_expanded.length
643
+ @word = [@word, word].join(ws).strip
644
+ set_string(@word, params[1])
645
+ else
646
+ @word = [@word, word].join(ws)
647
+ end
648
+
485
649
  nil
486
650
  end
487
651
  end
488
652
 
489
-
490
653
  class MultiplyNumber < FilterNumber
491
- def self.hint; 'Multiply the NTH number with NUM'; end
492
- def self.params; 'NTH,NUM'; end
654
+ def self.hint
655
+ "Multiply the NTH number with NUM"
656
+ end
493
657
 
494
- def filtered_number(num, param_num)
658
+ def self.params
659
+ "NTH,NUM"
660
+ end
661
+
662
+ def filtered_number(num, _param_num)
495
663
  num.to_i * params[1].to_i
496
664
  end
497
665
  end
498
666
 
499
-
500
667
  class Prepend < FilterBase
501
- def self.hint; 'Prepend the current target with TEXT'; end
502
- def self.params; 'TEXT'; end
668
+ def self.hint
669
+ "Prepend the current target with TEXT"
670
+ end
671
+
672
+ def self.params
673
+ "TEXT"
674
+ end
503
675
 
504
676
  def filter(params)
505
- super "#{params[0]}#{get_string}"
677
+ super("#{params[0]}#{get_string}")
506
678
  end
507
679
  end
508
680
 
509
-
510
681
  class PrependFrom < FilterBase
511
- def self.hint; 'Prepend the current target with the text from TARGET'; end
512
- def self.params; 'TARGET'; end
682
+ def self.hint
683
+ "Prepend the current target with the text from TARGET"
684
+ end
685
+
686
+ def self.params
687
+ "TARGET"
688
+ end
513
689
 
514
690
  def filter(params)
515
- super "#{get_string(params[0])}#{get_string}"
691
+ super("#{get_string(params[0])}#{get_string}")
516
692
  end
517
693
  end
518
694
 
519
-
520
695
  class PrependToNumber < FilterNumber
521
- def self.hint; 'Prepend the TEXT to the NTH number'; end
522
- def self.params; 'NTH,TEXT'; end
696
+ def self.hint
697
+ "Prepend the TEXT to the NTH number"
698
+ end
523
699
 
524
- def filtered_number(num, param_num)
700
+ def self.params
701
+ "NTH,TEXT"
702
+ end
703
+
704
+ def filtered_number(num, _param_num)
525
705
  "#{params[1]}#{num}"
526
706
  end
527
707
  end
528
708
 
529
-
530
709
  class PrependToWord < FilterWord
531
- def self.hint; 'Prepend the TEXT to the NTH word'; end
532
- def self.params; 'NTH,TEXT'; end
710
+ def self.hint
711
+ "Prepend the TEXT to the NTH word"
712
+ end
533
713
 
534
- def filtered_word(word, param_num)
714
+ def self.params
715
+ "NTH,TEXT"
716
+ end
717
+
718
+ def filtered_word(word, _param_num)
535
719
  params[1] + word
536
720
  end
537
721
  end
538
722
 
539
-
540
723
  class PrependWordFrom < FilterWord
541
- def self.hint; 'Prepend with TARGET the NTH word'; end
542
- def self.params; 'NTH,TARGET'; end
724
+ def self.hint
725
+ "Prepend with TARGET the NTH word"
726
+ end
727
+
728
+ def self.params
729
+ "NTH,TARGET"
730
+ end
543
731
 
544
732
  def string_to_loop
545
733
  get_string(params[1])
@@ -549,163 +737,239 @@ module FilterRename
549
737
  true
550
738
  end
551
739
 
552
- def filtered_word(word, param_num)
740
+ def filtered_word(word, _param_num)
553
741
  set_string([word, get_string].join(ws))
554
742
  word
555
743
  end
556
744
  end
557
745
 
558
-
559
746
  class Replace < FilterRegExp
560
- def self.hint; 'Replace the text matching REGEX with REPLACE'; end
561
- def self.params; 'REGEX,REPLACE'; end
747
+ def self.hint
748
+ "Replace the text matching REGEX with REPLACE"
749
+ end
562
750
 
563
- def filtered_regexp(matches, params)
751
+ def self.params
752
+ "REGEX,REPLACE"
753
+ end
754
+
755
+ def filtered_regexp(_matches, params)
564
756
  params[1]
565
757
  end
566
758
  end
567
759
 
568
-
569
760
  class ReplaceFrom < FilterRegExp
570
- def self.hint; 'Replace the REGEX matching text with the TARGET content'; end
571
- def self.params; 'REGEX,TARGET'; end
761
+ def self.hint
762
+ "Replace the REGEX matching text with the TARGET content"
763
+ end
572
764
 
573
- def filtered_regexp(matches, params)
765
+ def self.params
766
+ "REGEX,TARGET"
767
+ end
768
+
769
+ def filtered_regexp(_matches, params)
574
770
  get_string(params[1]).to_s
575
771
  end
576
772
  end
577
773
 
578
-
579
774
  class ReplaceNumber < FilterNumber
580
- def self.hint; 'Replace the NTH number with NUMBER'; end
581
- def self.params; 'NTH,NUMBER'; end
775
+ def self.hint
776
+ "Replace the NTH number with NUMBER"
777
+ end
582
778
 
583
- def filtered_number(num, param_num)
779
+ def self.params
780
+ "NTH,NUMBER"
781
+ end
782
+
783
+ def filtered_number(_num, _param_num)
584
784
  params[1]
585
785
  end
586
786
  end
587
787
 
588
-
589
788
  class ReplaceOccurrence < FilterOccurrence
590
- def self.hint; 'Replace the NTH occurrence of REGEXP with TEXT'; end
591
- def self.params; 'NTH,REGEXP,TEXT'; end
789
+ def self.hint
790
+ "Replace the NTH occurrence of REGEXP with TEXT"
791
+ end
592
792
 
593
- def filtered_occurrence(occurrence, param_num)
793
+ def self.params
794
+ "NTH,REGEXP,TEXT"
795
+ end
796
+
797
+ def filtered_occurrence(_occurrence, _param_num)
594
798
  params[2]
595
799
  end
596
800
  end
597
801
 
598
-
599
802
  class ReplaceWord < FilterWord
600
- def self.hint; 'Replace the NTH word with TEXT'; end
601
- def self.params; 'NTH,TEXT'; end
803
+ def self.hint
804
+ "Replace the NTH word with TEXT"
805
+ end
602
806
 
603
- def filtered_word(word, param_num)
807
+ def self.params
808
+ "NTH,TEXT"
809
+ end
810
+
811
+ def filtered_word(_word, _param_num)
604
812
  params[1]
605
813
  end
606
814
  end
607
815
 
608
-
609
816
  class ReplaceDate < FilterBase
610
- def self.hint; 'Replace a date from FORMATSRC to FORMATDEST (placeholders: <m>, <B>, <b>, <Y>, <d>)'; end
611
- def self.params; 'FORMATSRC,FORMATDEST[,LANG]'; end
817
+ def self.hint
818
+ "Replace a date from FORMATSRC to FORMATDEST (placeholders: <m>, <B>, <b>, <Y>, <d>)"
819
+ end
820
+
821
+ def self.params
822
+ "FORMATSRC,FORMATDEST[,LANG]"
823
+ end
612
824
 
613
825
  def filter(params)
614
826
  params[2] ||= get_config(:lang)
615
- super get_string.change_date_format(format_src: params[0], format_dest: params[1],
616
- long_months: get_words(:long_months , params[2]),
617
- short_months: get_words(:short_months , params[2]),
827
+ super(get_string.change_date_format(format_src: params[0], format_dest: params[1],
828
+ long_months: get_words(:long_months, params[2]),
829
+ short_months: get_words(:short_months, params[2]),
618
830
  long_days: get_words(:long_days, params[2]),
619
- short_days: get_words(:short_days, params[2]))
831
+ short_days: get_words(:short_days, params[2])))
620
832
  end
621
833
  end
622
834
 
623
-
624
835
  class Reverse < FilterBase
625
- def self.hint; 'Reverse the string'; end
626
- def self.params; nil; end
836
+ def self.hint
837
+ "Reverse the string"
838
+ end
627
839
 
628
- def filter(params)
629
- super get_string.reverse
840
+ def self.params
841
+ nil
630
842
  end
631
- end
632
843
 
844
+ def filter(_params)
845
+ super(get_string.reverse)
846
+ end
847
+ end
633
848
 
634
849
  class RightJustify < FilterBase
635
- def self.hint; 'Apply enough CHAR(s) to the left side to have a N-length string'; end
636
- def self.params; 'N,CHAR'; end
850
+ def self.hint
851
+ "Apply enough CHAR(s) to the left side to have a N-length string"
852
+ end
853
+
854
+ def self.params
855
+ "N,CHAR"
856
+ end
637
857
 
638
858
  def filter(params)
639
- super get_string.rjust(params[0].to_i, params[1])
859
+ super(get_string.rjust(params[0].to_i, params[1]))
640
860
  end
641
861
  end
642
862
 
643
-
644
863
  class Set < FilterBase
645
- def self.hint; 'Set the current or an optional TARGET with TEXT'; end
646
- def self.params; 'TEXT[,TARGET]'; end
864
+ def self.hint
865
+ "Set the current or an optional TARGET with TEXT"
866
+ end
867
+
868
+ def self.params
869
+ "TEXT[,TARGET]"
870
+ end
647
871
 
648
872
  def filter(params)
649
873
  if params[1].nil?
650
874
  str = params[0]
651
875
  else
652
- set_string(params[0], params[1].delete(':<>'))
876
+ set_string(params[0], params[1].delete(":<>"))
653
877
  str = get_string
654
878
  end
655
879
 
656
- super str
880
+ super(str)
657
881
  end
658
882
  end
659
883
 
884
+ class SetNumberWhen < FilterNumber
885
+ def self.hint
886
+ "Set the NTH number to NUMBER when CONDITION is matched"
887
+ end
888
+
889
+ def self.params
890
+ "NTH,CONDITION,NUMBER"
891
+ end
892
+
893
+ def filtered_number(num, _param_num)
894
+ if FilterNumber.calculator(num.to_i, params[-2])
895
+ FilterNumber.calculator(num.to_i, params[-1])
896
+ else
897
+ num
898
+ end
899
+ end
900
+ end
660
901
 
661
902
  class SetWhen < FilterBase
662
- def self.hint; 'Set the current or given TARGET to TEXT when REGEX is matched'; end
663
- def self.params; 'REGEX,TEXT[,TARGET]'; end
903
+ def self.hint
904
+ "Set the current or given TARGET to TEXT when REGEX is matched"
905
+ end
906
+
907
+ def self.params
908
+ "REGEX,TEXT[,TARGET]"
909
+ end
664
910
 
665
911
  def filter(params)
666
912
  target = params[-1] if params.length.odd?
667
913
  set_string(params[1], target) if get_string =~ Regexp.new(params[0], get_config(:ignore_case).to_boolean)
668
- super get_string
914
+ super(get_string)
669
915
  end
670
916
  end
671
917
 
672
-
673
918
  class Spacify < FilterBase
674
- def self.hint; 'Replace CHAR with a space'; end
675
- def self.params; 'CHAR1,CHAR2,...'; end
919
+ def self.hint
920
+ "Replace CHAR with a space"
921
+ end
922
+
923
+ def self.params
924
+ "CHAR1,CHAR2,..."
925
+ end
676
926
 
677
927
  def filter(params)
678
- regexp = Regexp.new(params.join('|'), get_config(:ignore_case).to_boolean)
679
- super get_string.gsub(regexp, ' ')
928
+ regexp = Regexp.new(params.join("|"), get_config(:ignore_case).to_boolean)
929
+ super(get_string.gsub(regexp, " "))
680
930
  end
681
931
  end
682
932
 
683
-
684
933
  class SplitWord < FilterWord
685
- def self.hint; 'Split the NTH word using a REGEX with capturing groups'; end
686
- def self.params; 'NTH,REGEX'; end
934
+ def self.hint
935
+ "Split the NTH word using a REGEX with capturing groups"
936
+ end
687
937
 
688
- def filtered_word(word, param_num)
938
+ def self.params
939
+ "NTH,REGEX"
940
+ end
941
+
942
+ def filtered_word(word, _param_num)
689
943
  word.scan(Regexp.new(wrap_regex(params[1]), get_config(:ignore_case))).pop.to_a.join(ws)
690
944
  end
691
945
  end
692
946
 
693
-
694
947
  class Squeeze < FilterBase
695
- def self.hint; 'Squeeze consecutive CHARS in only one'; end
696
- def self.params; 'CHAR'; end
948
+ def self.hint
949
+ "Squeeze consecutive CHARS in only one"
950
+ end
951
+
952
+ def self.params
953
+ "CHAR"
954
+ end
697
955
 
698
956
  def filter(params)
699
- super get_string.gsub Regexp.new("#{params[0]}{2,}", get_config(:ignore_case).to_boolean), params[0]
957
+ super(get_string.gsub Regexp.new("#{params[0]}{2,}", get_config(:ignore_case).to_boolean), params[0])
700
958
  end
701
959
  end
702
960
 
703
-
704
961
  class SwapNumber < FilterNumber
705
- def self.hint; 'Swap the NTH1 number with the NTH2'; end
706
- def self.params; 'NTH1,NTH2'; end
962
+ def self.hint
963
+ "Swap the NTH1 number with the NTH2"
964
+ end
707
965
 
708
- def indexed_params; 2; end
966
+ def self.params
967
+ "NTH1,NTH2"
968
+ end
969
+
970
+ def indexed_params
971
+ 2
972
+ end
709
973
 
710
974
  def filtered_number(num, param_num)
711
975
  case param_num
@@ -724,12 +988,18 @@ module FilterRename
724
988
  end
725
989
  end
726
990
 
727
-
728
991
  class SwapWord < FilterWord
729
- def self.hint; 'Swap the NTH1 word with the NTH2'; end
730
- def self.params; 'NTH1,NTH2'; end
992
+ def self.hint
993
+ "Swap the NTH1 word with the NTH2"
994
+ end
731
995
 
732
- def indexed_params; 2; end
996
+ def self.params
997
+ "NTH1,NTH2"
998
+ end
999
+
1000
+ def indexed_params
1001
+ 2
1002
+ end
733
1003
 
734
1004
  def filtered_word(word, param_num)
735
1005
  case param_num
@@ -748,20 +1018,28 @@ module FilterRename
748
1018
  end
749
1019
  end
750
1020
 
751
-
752
1021
  class Template < FilterBase
753
- def self.hint; 'Replace the <placeholders> in TEMPLATE with the relative targets'; end
754
- def self.params; 'TEMPLATE'; end
1022
+ def self.hint
1023
+ "Replace the <placeholders> in TEMPLATE with the relative targets"
1024
+ end
1025
+
1026
+ def self.params
1027
+ "TEMPLATE"
1028
+ end
755
1029
 
756
1030
  def filter(params)
757
- super params[0].gsub(/<([a-z0-9\_]+)>/) { get_string(Regexp.last_match[1]) }
1031
+ super(params[0].gsub(/<([a-z0-9_]+)>/) { get_string(Regexp.last_match[1]) })
758
1032
  end
759
1033
  end
760
1034
 
1035
+ class Translate < FilterBase
1036
+ def self.hint
1037
+ "Replace text in GROUP from SUBGRPSRC to SUBGRPDST"
1038
+ end
761
1039
 
762
- class TranslateWords < FilterBase
763
- def self.hint; 'Replace words in GROUP from SUBGRPS to SUBGRPD'; end
764
- def self.params; 'GROUP,SUBGRPS,SUBGRPD'; end
1040
+ def self.params
1041
+ "GROUP,SUBGRPSRC,SUBGRPDST"
1042
+ end
765
1043
 
766
1044
  def filter(params)
767
1045
  str = get_string
@@ -773,59 +1051,78 @@ module FilterRename
773
1051
  str = str.gsub(Regexp.new(x, get_config(:ignore_case)), get_words(group, lang_dest, i))
774
1052
  end
775
1053
 
776
- super str
1054
+ super(str)
777
1055
  end
778
1056
  end
779
1057
 
780
-
781
1058
  class Trim < FilterBase
782
- def self.hint; 'Remove trailing spaces'; end
783
- def self.params; nil; end
1059
+ def self.hint
1060
+ "Remove trailing spaces"
1061
+ end
784
1062
 
785
- def filter(params)
786
- super get_string.strip
1063
+ def self.params
1064
+ nil
787
1065
  end
788
- end
789
1066
 
1067
+ def filter(_params)
1068
+ super(get_string.strip)
1069
+ end
1070
+ end
790
1071
 
791
1072
  class Uppercase < FilterBase
792
- def self.hint; 'Uppercase each word'; end
793
- def self.params; nil; end
1073
+ def self.hint
1074
+ "Uppercase each word"
1075
+ end
794
1076
 
795
- def filter(params)
796
- super get_string.upcase
1077
+ def self.params
1078
+ nil
797
1079
  end
798
- end
799
1080
 
1081
+ def filter(_params)
1082
+ super(get_string.upcase)
1083
+ end
1084
+ end
800
1085
 
801
1086
  class UppercaseWord < FilterWord
802
- def self.hint; 'Uppercase the NTH word'; end
803
- def self.params; 'NTH'; end
1087
+ def self.hint
1088
+ "Uppercase the NTH word"
1089
+ end
804
1090
 
805
- def filtered_word(word, param_num)
1091
+ def self.params
1092
+ "NTH"
1093
+ end
1094
+
1095
+ def filtered_word(word, _param_num)
806
1096
  word.upcase
807
1097
  end
808
1098
  end
809
1099
 
810
-
811
1100
  class Wrap < FilterRegExp
812
- def self.hint; 'Wrap the text matching REGEX with SEPARATOR1 and SEPARATOR2'; end
813
- def self.params; 'REGEX,SEPARATOR1,SEPARATOR2'; end
1101
+ def self.hint
1102
+ "Wrap the text matching REGEX with SEPARATOR1 and SEPARATOR2"
1103
+ end
1104
+
1105
+ def self.params
1106
+ "REGEX,SEPARATOR1,SEPARATOR2"
1107
+ end
814
1108
 
815
1109
  def filtered_regexp(matches, params)
816
1110
  "#{params[1]}#{matches[0]}#{params[2]}"
817
1111
  end
818
1112
  end
819
1113
 
1114
+ class WrapWord < FilterWord
1115
+ def self.hint
1116
+ "Wrap the NTH word with SEPARATOR1 and SEPARATOR2"
1117
+ end
820
1118
 
821
- class WrapWords < FilterWord
822
- def self.hint; 'Wrap the NTH word with SEPARATOR1 and SEPARATOR2'; end
823
- def self.params; 'NTH,SEPARATOR1,SEPARATOR2'; end
1119
+ def self.params
1120
+ "NTH,SEPARATOR1,SEPARATOR2"
1121
+ end
824
1122
 
825
- def filtered_word(word, param_num)
1123
+ def filtered_word(word, _param_num)
826
1124
  "#{params[1]}#{word}#{params[2]}"
827
1125
  end
828
1126
  end
829
1127
  end
830
-
831
1128
  end