pdfh 3.0.2 → 3.0.3
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/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +5 -8
- data/Gemfile +1 -0
- data/Gemfile.lock +43 -30
- data/README.md +1 -1
- data/bin/run +1 -0
- data/lib/pdfh/models/document.rb +15 -11
- data/lib/pdfh/models/document_type.rb +11 -0
- data/lib/pdfh/models/settings.rb +2 -0
- data/lib/pdfh/utils/opt_parser.rb +2 -2
- data/lib/pdfh/utils/rename_validator.rb +44 -0
- data/lib/pdfh/version.rb +1 -1
- data/lib/pdfh.rb +1 -0
- data/pdfh.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae203433b71f3129de5d62505e63d8d1435b0463c82a22820b76e8ea8536de1c
|
4
|
+
data.tar.gz: 61ac5f4219b353778a0e9bc3b749050e0f535926583ad8d6e74325b5cecfe51b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5559496bf4652bbd0f63d3d8f056c9e39e248b7a18daae0669b5c3323f288f52ecf5bd15466de0025d948095ad04e46f1896ca367facdafe7a4c4eae48335a9
|
7
|
+
data.tar.gz: c7fdff58c2c3c42a550e9bd8a3acf376ac958fa60de2588c5e212f67199799f47724b75d0a540317069944bd881f99d857fd3a6880e480e75c66abad75704c7b
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2024-
|
3
|
+
# on 2024-03-13 18:36:20 UTC using RuboCop version 1.62.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -21,12 +21,7 @@ RSpec/AnyInstance:
|
|
21
21
|
Exclude:
|
22
22
|
- 'spec/pdfh/main_spec.rb'
|
23
23
|
|
24
|
-
# Offense count:
|
25
|
-
# Configuration parameters: CountAsOne.
|
26
|
-
RSpec/ExampleLength:
|
27
|
-
Max: 6
|
28
|
-
|
29
|
-
# Offense count: 7
|
24
|
+
# Offense count: 8
|
30
25
|
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
|
31
26
|
# Include: **/*_spec*rb*, **/spec/**/*
|
32
27
|
RSpec/FilePath:
|
@@ -37,9 +32,10 @@ RSpec/FilePath:
|
|
37
32
|
- 'spec/pdfh/utils/month_spec.rb'
|
38
33
|
- 'spec/pdfh/utils/opt_parser_spec.rb'
|
39
34
|
- 'spec/pdfh/utils/pdf_file_handler_spec.rb'
|
35
|
+
- 'spec/pdfh/utils/rename_validator_spec.rb'
|
40
36
|
- 'spec/pdfh/utils/settings_builder_spec.rb'
|
41
37
|
|
42
|
-
# Offense count:
|
38
|
+
# Offense count: 8
|
43
39
|
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
|
44
40
|
# Include: **/*_spec.rb
|
45
41
|
RSpec/SpecFilePathFormat:
|
@@ -51,6 +47,7 @@ RSpec/SpecFilePathFormat:
|
|
51
47
|
- 'spec/pdfh/utils/month_spec.rb'
|
52
48
|
- 'spec/pdfh/utils/opt_parser_spec.rb'
|
53
49
|
- 'spec/pdfh/utils/pdf_file_handler_spec.rb'
|
50
|
+
- 'spec/pdfh/utils/rename_validator_spec.rb'
|
54
51
|
- 'spec/pdfh/utils/settings_builder_spec.rb'
|
55
52
|
|
56
53
|
# Offense count: 3
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pdfh (3.0.
|
4
|
+
pdfh (3.0.3)
|
5
5
|
colorize (~> 1.1.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (7.1.2)
|
10
|
+
activesupport (7.1.3.2)
|
11
11
|
base64
|
12
12
|
bigdecimal
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
@@ -20,67 +20,79 @@ GEM
|
|
20
20
|
ansi (1.5.0)
|
21
21
|
ast (2.4.2)
|
22
22
|
base64 (0.2.0)
|
23
|
-
bigdecimal (3.1.
|
23
|
+
bigdecimal (3.1.6)
|
24
24
|
blockenspiel (0.5.0)
|
25
25
|
code-scanning-rubocop (0.6.1)
|
26
26
|
rubocop (~> 1.0)
|
27
27
|
coderay (1.1.3)
|
28
28
|
colorize (1.1.0)
|
29
|
-
concurrent-ruby (1.2.
|
29
|
+
concurrent-ruby (1.2.3)
|
30
30
|
connection_pool (2.4.1)
|
31
|
-
|
31
|
+
debug (1.9.1)
|
32
|
+
irb (~> 1.10)
|
33
|
+
reline (>= 0.3.8)
|
34
|
+
diff-lcs (1.5.1)
|
32
35
|
docile (1.4.0)
|
33
|
-
drb (2.2.
|
34
|
-
|
35
|
-
factory_bot (6.4.5)
|
36
|
+
drb (2.2.1)
|
37
|
+
factory_bot (6.4.6)
|
36
38
|
activesupport (>= 5.0.0)
|
37
|
-
i18n (1.14.
|
39
|
+
i18n (1.14.4)
|
38
40
|
concurrent-ruby (~> 1.0)
|
41
|
+
io-console (0.7.2)
|
42
|
+
irb (1.12.0)
|
43
|
+
rdoc
|
44
|
+
reline (>= 0.4.2)
|
39
45
|
json (2.7.1)
|
40
46
|
language_server-protocol (3.17.0.3)
|
41
47
|
method_source (1.0.0)
|
42
|
-
minitest (5.
|
48
|
+
minitest (5.22.2)
|
43
49
|
mutex_m (0.2.0)
|
44
50
|
parallel (1.24.0)
|
45
|
-
parser (3.3.0.
|
51
|
+
parser (3.3.0.5)
|
46
52
|
ast (~> 2.4.1)
|
47
53
|
racc
|
48
54
|
pry (0.14.2)
|
49
55
|
coderay (~> 1.1)
|
50
56
|
method_source (~> 1.0)
|
57
|
+
psych (5.1.2)
|
58
|
+
stringio
|
51
59
|
racc (1.7.3)
|
52
60
|
rainbow (3.1.1)
|
53
61
|
rake (13.1.0)
|
62
|
+
rdoc (6.6.2)
|
63
|
+
psych (>= 4.0.0)
|
54
64
|
regexp_parser (2.9.0)
|
65
|
+
reline (0.4.3)
|
66
|
+
io-console (~> 0.5)
|
55
67
|
rexml (3.2.6)
|
56
|
-
rspec (3.
|
57
|
-
rspec-core (~> 3.
|
58
|
-
rspec-expectations (~> 3.
|
59
|
-
rspec-mocks (~> 3.
|
60
|
-
rspec-core (3.
|
61
|
-
rspec-support (~> 3.
|
62
|
-
rspec-expectations (3.
|
68
|
+
rspec (3.13.0)
|
69
|
+
rspec-core (~> 3.13.0)
|
70
|
+
rspec-expectations (~> 3.13.0)
|
71
|
+
rspec-mocks (~> 3.13.0)
|
72
|
+
rspec-core (3.13.0)
|
73
|
+
rspec-support (~> 3.13.0)
|
74
|
+
rspec-expectations (3.13.0)
|
63
75
|
diff-lcs (>= 1.2.0, < 2.0)
|
64
|
-
rspec-support (~> 3.
|
65
|
-
rspec-mocks (3.
|
76
|
+
rspec-support (~> 3.13.0)
|
77
|
+
rspec-mocks (3.13.0)
|
66
78
|
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
-
rspec-support (~> 3.
|
68
|
-
rspec-support (3.
|
79
|
+
rspec-support (~> 3.13.0)
|
80
|
+
rspec-support (3.13.1)
|
69
81
|
rspec_junit_formatter (0.6.0)
|
70
82
|
rspec-core (>= 2, < 4, != 2.12.0)
|
71
|
-
rubocop (1.
|
83
|
+
rubocop (1.62.1)
|
72
84
|
json (~> 2.3)
|
73
85
|
language_server-protocol (>= 3.17.0)
|
74
86
|
parallel (~> 1.10)
|
75
|
-
parser (>= 3.
|
87
|
+
parser (>= 3.3.0.2)
|
76
88
|
rainbow (>= 2.2.2, < 4.0)
|
77
89
|
regexp_parser (>= 1.8, < 3.0)
|
78
90
|
rexml (>= 3.2.5, < 4.0)
|
79
|
-
rubocop-ast (>= 1.
|
91
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
80
92
|
ruby-progressbar (~> 1.7)
|
81
93
|
unicode-display_width (>= 2.4.0, < 3.0)
|
82
|
-
rubocop-ast (1.
|
83
|
-
parser (>= 3.
|
94
|
+
rubocop-ast (1.31.2)
|
95
|
+
parser (>= 3.3.0.4)
|
84
96
|
rubocop-capybara (2.20.0)
|
85
97
|
rubocop (~> 1.41)
|
86
98
|
rubocop-factory_bot (2.25.1)
|
@@ -90,12 +102,11 @@ GEM
|
|
90
102
|
rubocop-ast (>= 1.30.0, < 2.0)
|
91
103
|
rubocop-rake (0.6.0)
|
92
104
|
rubocop (~> 1.0)
|
93
|
-
rubocop-rspec (2.
|
105
|
+
rubocop-rspec (2.27.1)
|
94
106
|
rubocop (~> 1.40)
|
95
107
|
rubocop-capybara (~> 2.17)
|
96
108
|
rubocop-factory_bot (~> 2.22)
|
97
109
|
ruby-progressbar (1.13.0)
|
98
|
-
ruby2_keywords (0.0.5)
|
99
110
|
simplecov (0.22.0)
|
100
111
|
docile (~> 1.1)
|
101
112
|
simplecov-html (~> 0.11)
|
@@ -106,6 +117,7 @@ GEM
|
|
106
117
|
terminal-table
|
107
118
|
simplecov-html (0.12.3)
|
108
119
|
simplecov_json_formatter (0.1.4)
|
120
|
+
stringio (3.1.0)
|
109
121
|
terminal-table (3.0.2)
|
110
122
|
unicode-display_width (>= 1.1.1, < 3)
|
111
123
|
tzinfo (2.0.6)
|
@@ -120,6 +132,7 @@ PLATFORMS
|
|
120
132
|
DEPENDENCIES
|
121
133
|
bundler (~> 2.0)
|
122
134
|
code-scanning-rubocop (~> 0.5)
|
135
|
+
debug (~> 1.8)
|
123
136
|
factory_bot (~> 6.2)
|
124
137
|
pdfh!
|
125
138
|
pry (~> 0.14)
|
@@ -135,4 +148,4 @@ DEPENDENCIES
|
|
135
148
|
versionomy (~> 0.5)
|
136
149
|
|
137
150
|
BUNDLED WITH
|
138
|
-
2.5.
|
151
|
+
2.5.6
|
data/README.md
CHANGED
@@ -97,7 +97,7 @@ Everyone interacting in the Pdfh project’s codebases, issue trackers, chat roo
|
|
97
97
|
<!-- Links -->
|
98
98
|
[rubocop-img]: https://github.com/iax7/pdfh/actions/workflows/rubocop-analysis.yml/badge.svg
|
99
99
|
[rubocop-url]: https://github.com/iax7/pdfh/actions/workflows/rubocop-analysis.yml
|
100
|
-
[ruby-img]: https://img.shields.io/badge/ruby-3.
|
100
|
+
[ruby-img]: https://img.shields.io/badge/ruby-3.3-blue?style=flat&logo=ruby&logoColor=CC342D&labelColor=white
|
101
101
|
[ruby-url]: https://www.ruby-lang.org/en/
|
102
102
|
[cc-img]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=00&labelColor=fff
|
103
103
|
[cc-url]: https://conventionalcommits.org
|
data/bin/run
CHANGED
data/lib/pdfh/models/document.rb
CHANGED
@@ -60,7 +60,7 @@ module Pdfh
|
|
60
60
|
|
61
61
|
# @return [String]
|
62
62
|
def type_name
|
63
|
-
|
63
|
+
type&.name&.titleize || "N/A"
|
64
64
|
end
|
65
65
|
|
66
66
|
# @return [String]
|
@@ -68,18 +68,22 @@ module Pdfh
|
|
68
68
|
@sub_type&.name&.titleize || "N/A"
|
69
69
|
end
|
70
70
|
|
71
|
+
# @return [Hash{Symbol->String}]
|
72
|
+
def rename_data
|
73
|
+
{
|
74
|
+
original: file_name_only,
|
75
|
+
period: period.to_s,
|
76
|
+
year: period.year.to_s,
|
77
|
+
month: period.month.to_s,
|
78
|
+
type: type_name,
|
79
|
+
subtype: sub_type,
|
80
|
+
extra: extra || ""
|
81
|
+
}.freeze
|
82
|
+
end
|
83
|
+
|
71
84
|
# @return [String]
|
72
85
|
def new_name
|
73
|
-
|
74
|
-
new_name = template
|
75
|
-
.sub("{original}", file_name_only)
|
76
|
-
.sub("{period}", period.to_s)
|
77
|
-
.sub("{year}", period.year.to_s)
|
78
|
-
.sub("{month}", period.month.to_s)
|
79
|
-
.sub("{type}", type_name)
|
80
|
-
.sub("{subtype}", sub_type)
|
81
|
-
.sub("{extra}", extra || "")
|
82
|
-
"#{new_name}.pdf"
|
86
|
+
type.generate_new_name(rename_data)
|
83
87
|
end
|
84
88
|
|
85
89
|
# @return [String]
|
@@ -11,6 +11,11 @@ module Pdfh
|
|
11
11
|
self.re_file = Regexp.new(re_file)
|
12
12
|
self.re_date = Regexp.new(re_date)
|
13
13
|
self.sub_types = extract_subtype(sub_types) if sub_types
|
14
|
+
@rename_validator = RenameValidator.new(name_template)
|
15
|
+
return if @rename_validator.valid?
|
16
|
+
|
17
|
+
errors = @rename_validator.unknown.join(", ")
|
18
|
+
raise ArgumentError, "Document type #{name.inspect} has invalid :name_template. Tokens not recognized: #{errors}"
|
14
19
|
end
|
15
20
|
|
16
21
|
# removes special characters from string and replaces spaces with dashes
|
@@ -35,6 +40,12 @@ module Pdfh
|
|
35
40
|
pwd
|
36
41
|
end
|
37
42
|
|
43
|
+
# @param values [Hash{Symbol->String}
|
44
|
+
# @return [String]
|
45
|
+
def generate_new_name(values)
|
46
|
+
@rename_validator.name(values)
|
47
|
+
end
|
48
|
+
|
38
49
|
private
|
39
50
|
|
40
51
|
# @return [boolean]
|
data/lib/pdfh/models/settings.rb
CHANGED
@@ -49,12 +49,12 @@ module Pdfh
|
|
49
49
|
# @return [nil]
|
50
50
|
def list_types
|
51
51
|
settings = SettingsBuilder.build
|
52
|
-
ident =
|
52
|
+
ident = 2
|
53
53
|
max_width = settings.document_types.map { |t| t.gid.size }.max
|
54
54
|
puts "#{" " * ident}#{"ID".ljust(max_width)} Type Name"
|
55
55
|
puts "#{" " * ident}#{"—" * max_width} #{"—" * 23}"
|
56
56
|
settings.document_types.each do |type|
|
57
|
-
puts "#{" " * ident}#{type.gid.ljust(max_width).yellow} #{type.name
|
57
|
+
puts "#{" " * ident}#{type.gid.ljust(max_width).yellow} #{type.name}"
|
58
58
|
end
|
59
59
|
nil
|
60
60
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pdfh
|
4
|
+
# Validates the rename template, and generate new name
|
5
|
+
class RenameValidator
|
6
|
+
RENAME_TYPES = {
|
7
|
+
"original" => "No name change",
|
8
|
+
"period" => "Year-Month",
|
9
|
+
"year" => "Year",
|
10
|
+
"month" => "Month",
|
11
|
+
"type" => "Document Type name",
|
12
|
+
"subtype" => "Document Subtype name",
|
13
|
+
"extra" => "Extra data extracted from date_re"
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
attr_reader :name_template, :all, :unknown, :valid
|
17
|
+
|
18
|
+
# @param name_template [String]
|
19
|
+
# @return [self]
|
20
|
+
def initialize(name_template)
|
21
|
+
@name_template = name_template
|
22
|
+
@all = name_template.scan(/{(\w+)}/).flatten
|
23
|
+
@unknown = all - types
|
24
|
+
@valid = all - unknown
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Array<String>]
|
28
|
+
def types
|
29
|
+
RENAME_TYPES.keys
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Boolean]
|
33
|
+
def valid?
|
34
|
+
unknown.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
# @param values [Hash{Symbol->String}]
|
38
|
+
# @return [String (frozen)]
|
39
|
+
def name(values)
|
40
|
+
new_name = name_template.gsub("{", "%{") % values
|
41
|
+
"#{new_name}.pdf"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/pdfh/version.rb
CHANGED
data/lib/pdfh.rb
CHANGED
@@ -22,6 +22,7 @@ require_relative "pdfh/utils/month"
|
|
22
22
|
require_relative "pdfh/utils/opt_parser"
|
23
23
|
require_relative "pdfh/utils/options"
|
24
24
|
require_relative "pdfh/utils/pdf_file_handler"
|
25
|
+
require_relative "pdfh/utils/rename_validator"
|
25
26
|
require_relative "pdfh/utils/settings_builder"
|
26
27
|
|
27
28
|
require_relative "pdfh/main"
|
data/pdfh.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.metadata["homepage_uri"] = spec.homepage
|
22
22
|
spec.metadata["source_code_uri"] = spec.homepage
|
23
|
-
spec.metadata["changelog_uri"] = URI.join(spec.homepage, "CHANGELOG.md").to_s
|
23
|
+
spec.metadata["changelog_uri"] = URI.join(spec.homepage, "/blob/master/CHANGELOG.md").to_s
|
24
24
|
|
25
25
|
# Specify which files should be added to the gem when it is released.
|
26
26
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaias Piña
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/pdfh/utils/opt_parser.rb
|
65
65
|
- lib/pdfh/utils/options.rb
|
66
66
|
- lib/pdfh/utils/pdf_file_handler.rb
|
67
|
+
- lib/pdfh/utils/rename_validator.rb
|
67
68
|
- lib/pdfh/utils/settings_builder.rb
|
68
69
|
- lib/pdfh/version.rb
|
69
70
|
- pdfh.gemspec
|
@@ -74,7 +75,7 @@ metadata:
|
|
74
75
|
allowed_push_host: https://rubygems.org
|
75
76
|
homepage_uri: https://github.com/iax7/pdfh
|
76
77
|
source_code_uri: https://github.com/iax7/pdfh
|
77
|
-
changelog_uri: https://github.com/
|
78
|
+
changelog_uri: https://github.com/blob/master/CHANGELOG.md
|
78
79
|
rubygems_mfa_required: 'true'
|
79
80
|
post_install_message:
|
80
81
|
rdoc_options: []
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
- !ruby/object:Gem::Version
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
|
-
rubygems_version: 3.5.
|
95
|
+
rubygems_version: 3.5.6
|
95
96
|
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: Organize PDF files
|