pdfh 3.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e56c6dcb8915785a475e34a5120d44556fd6630d3738849161697b76ded58fa6
4
- data.tar.gz: 335b684595f23f61607d3ff3e0c6ed106da1e52842090c4ddc89381252f5771a
3
+ metadata.gz: ae203433b71f3129de5d62505e63d8d1435b0463c82a22820b76e8ea8536de1c
4
+ data.tar.gz: 61ac5f4219b353778a0e9bc3b749050e0f535926583ad8d6e74325b5cecfe51b
5
5
  SHA512:
6
- metadata.gz: 45bbfee057aeda92595c687b67a3e2f34c8ed4f36f28dbc5b3880fafb05f7a9e170b70e1ec61bc21709ba7ed3a1401667fca03cadf35593fb8843b93ee7fdfdb
7
- data.tar.gz: 930644f381d3e338ec3161d8346179f3268c336bf3407ae64ed256eb9c30b0bd2b0d0bcf6c0ab31c2d0a57a25d56f05fd0f99bf89f7978be77a0d78f985da101
6
+ metadata.gz: f5559496bf4652bbd0f63d3d8f056c9e39e248b7a18daae0669b5c3323f288f52ecf5bd15466de0025d948095ad04e46f1896ca367facdafe7a4c4eae48335a9
7
+ data.tar.gz: c7fdff58c2c3c42a550e9bd8a3acf376ac958fa60de2588c5e212f67199799f47724b75d0a540317069944bd881f99d857fd3a6880e480e75c66abad75704c7b
data/.rubocop.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
3
  require:
4
+ - rubocop-factory_bot
4
5
  - rubocop-performance
5
6
  - rubocop-rake
6
7
  - rubocop-rspec
@@ -25,3 +26,6 @@ Style/StringLiterals:
25
26
  Style/StringLiteralsInInterpolation:
26
27
  Enabled: true
27
28
  EnforcedStyle: double_quotes
29
+
30
+ Layout/HashAlignment:
31
+ EnforcedHashRocketStyle: table
data/.rubocop_todo.yml CHANGED
@@ -1,22 +1,16 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2023-07-13 05:43:39 UTC using RuboCop version 1.54.1.
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
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 7
9
+ # Offense count: 8
10
10
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
11
11
  Metrics/AbcSize:
12
12
  Max: 25
13
13
 
14
- # Offense count: 1
15
- # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
16
- # AllowedMethods: refine
17
- Metrics/BlockLength:
18
- Max: 26
19
-
20
14
  # Offense count: 6
21
15
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
22
16
  Metrics/MethodLength:
@@ -27,26 +21,34 @@ RSpec/AnyInstance:
27
21
  Exclude:
28
22
  - 'spec/pdfh/main_spec.rb'
29
23
 
30
- # Offense count: 1
31
- # Configuration parameters: CountAsOne.
32
- RSpec/ExampleLength:
33
- Max: 7
34
-
35
- # Offense count: 2
36
- RSpec/MultipleExpectations:
37
- Max: 2
38
-
39
- # Offense count: 1
40
- # Configuration parameters: AllowedPatterns.
41
- # AllowedPatterns: ^expect_, ^assert_
42
- RSpec/NoExpectationExample:
24
+ # Offense count: 8
25
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
26
+ # Include: **/*_spec*rb*, **/spec/**/*
27
+ RSpec/FilePath:
43
28
  Exclude:
44
- - 'spec/pdfh/pdf_handler_spec.rb'
45
-
46
- # Offense count: 1
47
- RSpec/SubjectStub:
29
+ - 'spec/pdfh/models/document_period_spec.rb'
30
+ - 'spec/pdfh/models/document_spec.rb'
31
+ - 'spec/pdfh/utils/console_spec.rb'
32
+ - 'spec/pdfh/utils/month_spec.rb'
33
+ - 'spec/pdfh/utils/opt_parser_spec.rb'
34
+ - 'spec/pdfh/utils/pdf_file_handler_spec.rb'
35
+ - 'spec/pdfh/utils/rename_validator_spec.rb'
36
+ - 'spec/pdfh/utils/settings_builder_spec.rb'
37
+
38
+ # Offense count: 8
39
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
40
+ # Include: **/*_spec.rb
41
+ RSpec/SpecFilePathFormat:
48
42
  Exclude:
49
- - 'spec/pdfh/main_spec.rb'
43
+ - '**/spec/routing/**/*'
44
+ - 'spec/pdfh/models/document_period_spec.rb'
45
+ - 'spec/pdfh/models/document_spec.rb'
46
+ - 'spec/pdfh/utils/console_spec.rb'
47
+ - 'spec/pdfh/utils/month_spec.rb'
48
+ - 'spec/pdfh/utils/opt_parser_spec.rb'
49
+ - 'spec/pdfh/utils/pdf_file_handler_spec.rb'
50
+ - 'spec/pdfh/utils/rename_validator_spec.rb'
51
+ - 'spec/pdfh/utils/settings_builder_spec.rb'
50
52
 
51
53
  # Offense count: 3
52
54
  # This cop supports safe autocorrection (--autocorrect).
data/CHANGELOG.md CHANGED
@@ -1,31 +1,40 @@
1
+ ## v3.0.2
2
+ - Fix `undefined method` when an invalid option is provided
3
+ - Fix and add tests to get above 90% coverage
4
+
5
+ ## v3.0.1
6
+ - Refactor classes for better readability
7
+ - Upgrade to Ruby v3.3.0 and require at least Ruby 3.0.0
8
+ - Upgrade gem dependencies
9
+
1
10
  ## v3.0.0
2
- * Migrate to `asdf` from `rvm`
3
- * Upgrade old gems
4
- * Bump to v3 (as this is project's third iteration)
11
+ - Migrate to `asdf` from `rvm`
12
+ - Upgrade old gems
13
+ - Bump to v3 (as this is project's third iteration)
5
14
 
6
15
  ## v0.2.0
7
- * Major gem refactoring
8
- * Change setting `base_path` to `destination_base_path`
9
- * Add DocumentType listing option on executable file
10
- * Add process individual documents providing type and files
16
+ - Major gem refactoring
17
+ - Change setting `base_path` to `destination_base_path`
18
+ - Add DocumentType listing option on executable file
19
+ - Add process individual documents providing type and files
11
20
  ```bash
12
21
  pdfh -t document_type_id path/to_files.pdf
13
22
  ```
14
- * Add `settings.yml` template in order to create a sample file
23
+ - Add `settings.yml` template in order to create a sample file
15
24
 
16
25
  ## v0.1.9
17
- * Add dependencies validation at run
26
+ - Add dependencies validation at run
18
27
 
19
28
  ## v0.1.5
20
- * Add `print_cmd` field in config file for information purposes
21
- * Settings now validates an unexisting directory
22
- * Refactor for easier maintenance
29
+ - Add `print_cmd` field in config file for information purposes
30
+ - Settings now validates an unexisting directory
31
+ - Refactor for easier maintenance
23
32
 
24
33
  ## v0.1.4
25
- * Add titleize format when writing new file
34
+ - Add titleize format when writing new file
26
35
 
27
36
  ## v0.1.3
28
- * Fixed copy companion files, which was not copying the files.
37
+ - Fixed copy companion files, which was not copying the files.
29
38
 
30
39
  ## v0.1.2
31
- * Initial Release
40
+ - Initial Release
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gemspec
7
7
 
8
8
  gem "bundler", "~> 2.0"
9
9
  gem "code-scanning-rubocop", "~> 0.5"
10
+ gem "debug", "~> 1.8"
10
11
  gem "factory_bot", "~> 6.2"
11
12
  gem "pry", "~> 0.14"
12
13
  gem "rake", "~> 13.0"
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pdfh (3.0.1)
5
- colorize (~> 0.8.0)
4
+ pdfh (3.0.3)
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.5)
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
- colorize (0.8.1)
29
- concurrent-ruby (1.2.2)
28
+ colorize (1.1.0)
29
+ concurrent-ruby (1.2.3)
30
30
  connection_pool (2.4.1)
31
- diff-lcs (1.5.0)
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.0)
34
- ruby2_keywords
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.1)
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.20.0)
48
+ minitest (5.22.2)
43
49
  mutex_m (0.2.0)
44
50
  parallel (1.24.0)
45
- parser (3.3.0.2)
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.12.0)
57
- rspec-core (~> 3.12.0)
58
- rspec-expectations (~> 3.12.0)
59
- rspec-mocks (~> 3.12.0)
60
- rspec-core (3.12.2)
61
- rspec-support (~> 3.12.0)
62
- rspec-expectations (3.12.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.12.0)
65
- rspec-mocks (3.12.6)
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.12.0)
68
- rspec-support (3.12.1)
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.59.0)
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.2.2.4)
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.30.0, < 2.0)
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.30.0)
83
- parser (>= 3.2.1.0)
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.26.1)
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.4
151
+ 2.5.6
data/README.md CHANGED
@@ -76,6 +76,12 @@ build pdfh.gemspec
76
76
  gem install pdfh-*
77
77
  ```
78
78
 
79
+ ### Conventional Commits
80
+ ```bash
81
+ npm install -g @commitlint/cli @commitlint/config-conventional
82
+ commitlint --from origin --to @
83
+ ```
84
+
79
85
  ## Contributing
80
86
 
81
87
  Bug reports and pull requests are welcome on GitHub at https://github.com/iax7/pdfh. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -91,7 +97,7 @@ Everyone interacting in the Pdfh project’s codebases, issue trackers, chat roo
91
97
  <!-- Links -->
92
98
  [rubocop-img]: https://github.com/iax7/pdfh/actions/workflows/rubocop-analysis.yml/badge.svg
93
99
  [rubocop-url]: https://github.com/iax7/pdfh/actions/workflows/rubocop-analysis.yml
94
- [ruby-img]: https://img.shields.io/badge/ruby-3.1-blue?style=flat&logo=ruby&logoColor=CC342D&labelColor=white
100
+ [ruby-img]: https://img.shields.io/badge/ruby-3.3-blue?style=flat&logo=ruby&logoColor=CC342D&labelColor=white
95
101
  [ruby-url]: https://www.ruby-lang.org/en/
96
102
  [cc-img]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=00&labelColor=fff
97
103
  [cc-url]: https://conventionalcommits.org
data/bin/run CHANGED
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "bundler/setup"
5
+ require "debug"
5
6
  require "pdfh"
6
7
  require "pry"
7
8
 
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ }
@@ -60,7 +60,7 @@ module Pdfh
60
60
 
61
61
  # @return [String]
62
62
  def type_name
63
- @type&.name&.titleize || "N/A"
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
- template = @type.name_template
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]
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pdfh
4
+ # Provides a way to divide document type by subtypes, for different name, and month adjustments
5
+ DocumentSubType = Struct.new(:name, :month_offset, keyword_init: true)
6
+ end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pdfh
4
- DocumentSubType = Struct.new(:name, :month_offset, keyword_init: true)
5
-
4
+ # Represents a type of document that can be processed by pdfh
6
5
  DocumentType = Struct.new(:name, :re_file, :re_date, :pwd, :store_path, :name_template, :sub_types, :print_cmd,
7
6
  keyword_init: true) do
8
7
  # @return [self]
@@ -12,6 +11,11 @@ module Pdfh
12
11
  self.re_file = Regexp.new(re_file)
13
12
  self.re_date = Regexp.new(re_date)
14
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}"
15
19
  end
16
20
 
17
21
  # removes special characters from string and replaces spaces with dashes
@@ -36,6 +40,12 @@ module Pdfh
36
40
  pwd
37
41
  end
38
42
 
43
+ # @param values [Hash{Symbol->String}
44
+ # @return [String]
45
+ def generate_new_name(values)
46
+ @rename_validator.name(values)
47
+ end
48
+
39
49
  private
40
50
 
41
51
  # @return [boolean]
@@ -55,6 +55,8 @@ module Pdfh
55
55
  @document_types = doc_types.each_with_object({}) do |data, result|
56
56
  doc_type = DocumentType.new(data)
57
57
  result.store(doc_type.gid, doc_type)
58
+ rescue ArgumentError => e
59
+ Pdfh.error_print e.message, exit_app: false
58
60
  end
59
61
  end
60
62
  end
@@ -13,25 +13,9 @@ module Pdfh
13
13
  opts.separator "Specific options:"
14
14
 
15
15
  opts.on("-tID", "--type=ID", "Document type id (requires a trailing file list)")
16
- opts.on_tail("-T", "--list-types", "List document types in configuration") do
17
- settings = SettingsBuilder.build
18
- ident = 4
19
- max_width = settings.document_types.map { |t| t.gid.size }.max
20
- puts "#{" " * ident}#{"ID".ljust(max_width)} Type Name"
21
- puts "#{" " * ident}#{"—" * max_width} #{"—" * 23}"
22
- settings.document_types.each do |type|
23
- puts "#{" " * ident}#{type.gid.ljust(max_width).yellow} #{type.name.inspect}"
24
- end
25
- exit
26
- end
27
- opts.on_tail("-V", "--version", "Show version") do
28
- puts "#{opts.program_name} v#{Pdfh::VERSION}"
29
- exit
30
- end
31
- opts.on_tail("-h", "--help", "help (this dialog)") do
32
- puts opts
33
- exit
34
- end
16
+ opts.on_tail("-T", "--list-types", "List document types in configuration") { list_types || exit }
17
+ opts.on_tail("-V", "--version", "Show version") { version || exit }
18
+ opts.on_tail("-h", "--help", "help (this dialog)") { help || exit }
35
19
 
36
20
  opts.on("-v", "--verbose", "Show more output. Useful for debug")
37
21
  opts.on("-d", "--dry", "Dry run, does not write new pdf")
@@ -47,10 +31,33 @@ module Pdfh
47
31
  options[:files] = ARGV if ARGV.any?
48
32
  options.transform_keys { |key| key.to_s.tr("-", "_").to_sym }
49
33
  rescue OptionParser::InvalidOption => e
50
- error_print e.message, exit_app: false
34
+ Pdfh.error_print(e.message, exit_app: false)
51
35
  puts OPT_PARSER.help
52
36
  exit 1
53
37
  end
38
+
39
+ # @return [nil]
40
+ def version
41
+ puts "#{OPT_PARSER.program_name} v#{Pdfh::VERSION}"
42
+ end
43
+
44
+ # @return [nil]
45
+ def help
46
+ puts OPT_PARSER
47
+ end
48
+
49
+ # @return [nil]
50
+ def list_types
51
+ settings = SettingsBuilder.build
52
+ ident = 2
53
+ max_width = settings.document_types.map { |t| t.gid.size }.max
54
+ puts "#{" " * ident}#{"ID".ljust(max_width)} Type Name"
55
+ puts "#{" " * ident}#{"—" * max_width} #{"—" * 23}"
56
+ settings.document_types.each do |type|
57
+ puts "#{" " * ident}#{type.gid.ljust(max_width).yellow} #{type.name}"
58
+ end
59
+ nil
60
+ end
54
61
  end
55
62
  end
56
63
  end
@@ -11,7 +11,7 @@ module Pdfh
11
11
  @verbose = arg_options[:verbose]
12
12
  @dry = arg_options[:dry]
13
13
  @type = arg_options[:type]
14
- @files = arg_options[:files]
14
+ @files = arg_options[:files] || []
15
15
  @mode = type ? :file : :directory
16
16
  end
17
17
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pdfh
4
- VERSION = "3.0.1"
4
+ VERSION = "3.0.3"
5
5
  end
data/lib/pdfh.rb CHANGED
@@ -12,6 +12,7 @@ require_relative "ext/string"
12
12
  # Models
13
13
  require_relative "pdfh/models/document"
14
14
  require_relative "pdfh/models/document_period"
15
+ require_relative "pdfh/models/document_sub_type"
15
16
  require_relative "pdfh/models/document_type"
16
17
  require_relative "pdfh/models/settings"
17
18
 
@@ -21,6 +22,7 @@ require_relative "pdfh/utils/month"
21
22
  require_relative "pdfh/utils/opt_parser"
22
23
  require_relative "pdfh/utils/options"
23
24
  require_relative "pdfh/utils/pdf_file_handler"
25
+ require_relative "pdfh/utils/rename_validator"
24
26
  require_relative "pdfh/utils/settings_builder"
25
27
 
26
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.
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ["lib"]
33
33
 
34
34
  # Uncomment to register a new dependency of your gem
35
- spec.add_dependency "colorize", "~> 0.8.0"
35
+ spec.add_dependency "colorize", "~> 1.1.0"
36
36
 
37
37
  # For more information and examples about making a new gem, checkout our
38
38
  # guide at: https://bundler.io/guides/creating_gem.html
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.1
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-01-09 00:00:00.000000000 Z
11
+ date: 2024-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.0
19
+ version: 1.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.0
26
+ version: 1.1.0
27
27
  description: Examine all PDF files in Look up directories, remove password (if has
28
28
  one), rename and copy to a new directory using regular expressions.
29
29
  email:
@@ -48,12 +48,14 @@ files:
48
48
  - bin/console
49
49
  - bin/run
50
50
  - bin/setup
51
+ - commitlint.config.js
51
52
  - exe/pdfh
52
53
  - lib/ext/string.rb
53
54
  - lib/pdfh.rb
54
55
  - lib/pdfh/main.rb
55
56
  - lib/pdfh/models/document.rb
56
57
  - lib/pdfh/models/document_period.rb
58
+ - lib/pdfh/models/document_sub_type.rb
57
59
  - lib/pdfh/models/document_type.rb
58
60
  - lib/pdfh/models/settings.rb
59
61
  - lib/pdfh/settings_template.rb
@@ -62,6 +64,7 @@ files:
62
64
  - lib/pdfh/utils/opt_parser.rb
63
65
  - lib/pdfh/utils/options.rb
64
66
  - lib/pdfh/utils/pdf_file_handler.rb
67
+ - lib/pdfh/utils/rename_validator.rb
65
68
  - lib/pdfh/utils/settings_builder.rb
66
69
  - lib/pdfh/version.rb
67
70
  - pdfh.gemspec
@@ -72,7 +75,7 @@ metadata:
72
75
  allowed_push_host: https://rubygems.org
73
76
  homepage_uri: https://github.com/iax7/pdfh
74
77
  source_code_uri: https://github.com/iax7/pdfh
75
- changelog_uri: https://github.com/iax7/CHANGELOG.md
78
+ changelog_uri: https://github.com/blob/master/CHANGELOG.md
76
79
  rubygems_mfa_required: 'true'
77
80
  post_install_message:
78
81
  rdoc_options: []
@@ -89,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
92
  - !ruby/object:Gem::Version
90
93
  version: '0'
91
94
  requirements: []
92
- rubygems_version: 3.5.3
95
+ rubygems_version: 3.5.6
93
96
  signing_key:
94
97
  specification_version: 4
95
98
  summary: Organize PDF files