pdfh 0.1.9 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14832944087c61f4949fe3fd42cdb848ebfd8a8931826cbd3e4fc111f5813a31
4
- data.tar.gz: 16c139cc38b766307fe4fe9a21b740161af8fffcc05b5c8397cfdde843b1b943
3
+ metadata.gz: ce33aa4da82a840716b3af1e3ae8a755075c991afd361da6916ba3418c523ba4
4
+ data.tar.gz: 49618addd2323056b8312b9a8bba29947623fcdfd4813c671a34078e7fe8ff57
5
5
  SHA512:
6
- metadata.gz: b0c320fcead6ae5e09a37ba17100837d392017b73fa0cd54b5d4126bebc52bd07f009457af741128df8197c67fb52d82eee2422a16b6240930f9e72ff795a950
7
- data.tar.gz: 335af04d4f5753d39e4464be53a24986f89dff1cc1e9fa2866e8340680317337cf3b24eb043cdbcdef5051fa47d45dcfe67ab685b289173dc42e789d5014e3c6
6
+ metadata.gz: 5d64fbcff7d7aed4a3e085ec42c6980be840abddce68faa50d064074957262e6e475cb803b379a71ed8b9d86f6d3a821f7aacc8610fcc3745c61ba8df97c3abc
7
+ data.tar.gz: '069fe2a97fbceeb475116cfab0b27666ce73613d1a13b5af46c8e2026eb13d35bbe593376bca4fdd34591e2fba58ffcc2b4d1104b00cd386bef85e7bda18fe9f'
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ *.yml
2
+
1
3
  .yardoc/
2
4
  _yardoc/
3
5
  coverage/
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
1
+ --format progress
2
2
  --color
3
3
  --require spec_helper
data/.rubocop.yml CHANGED
@@ -9,12 +9,14 @@ AllCops:
9
9
  NewCops: enable
10
10
  TargetRubyVersion: 2.5
11
11
  Exclude:
12
+ - doc/**/*
12
13
  - pkg/**/*
13
14
  - tmp/**/*
15
+ - vendor/**/*
14
16
 
15
17
  Layout/LineLength:
16
18
  Max: 120
17
- IgnoredPatterns: ['^\s*#']
19
+ AllowedPatterns: ['^\s*#']
18
20
 
19
21
  Style/StringLiterals:
20
22
  Enabled: true
data/.rubocop_todo.yml CHANGED
@@ -1,152 +1,47 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2021-03-02 12:13:30 UTC using RuboCop version 1.11.0.
3
+ # on 2021-05-15 01:26:47 UTC using RuboCop version 1.14.0.
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: 1
9
+ # Offense count: 5
10
10
  # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
11
11
  Metrics/AbcSize:
12
- Max: 23
12
+ Max: 24
13
13
 
14
- # Offense count: 4
14
+ # Offense count: 6
15
15
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
16
16
  # IgnoredMethods: refine
17
17
  Metrics/BlockLength:
18
- Max: 144
18
+ Max: 87
19
19
 
20
20
  # Offense count: 1
21
21
  # Configuration parameters: CountComments, CountAsOne.
22
22
  Metrics/ClassLength:
23
- Max: 149
23
+ Max: 121
24
24
 
25
- # Offense count: 5
25
+ # Offense count: 6
26
26
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
27
27
  Metrics/MethodLength:
28
- Max: 13
28
+ Max: 17
29
29
 
30
30
  # Offense count: 2
31
31
  RSpec/AnyInstance:
32
32
  Exclude:
33
- - 'spec/pdfh_spec.rb'
34
-
35
- # Offense count: 13
36
- # Cop supports --auto-correct.
37
- RSpec/ContextMethod:
38
- Exclude:
39
- - 'spec/classes/document_spec.rb'
40
- - 'spec/classes/month_spec.rb'
41
- - 'spec/classes/pdf_handler_spec.rb'
42
- - 'spec/classes/settings_spec.rb'
43
- - 'spec/pdfh_spec.rb'
44
-
45
- # Offense count: 13
46
- # Configuration parameters: Prefixes.
47
- # Prefixes: when, with, without
48
- RSpec/ContextWording:
49
- Exclude:
50
- - 'spec/classes/document_spec.rb'
51
- - 'spec/classes/month_spec.rb'
52
- - 'spec/classes/pdf_handler_spec.rb'
53
- - 'spec/classes/settings_spec.rb'
54
- - 'spec/pdfh_spec.rb'
33
+ - 'spec/pdfh/document_processor_spec.rb'
55
34
 
56
35
  # Offense count: 1
57
- # Cop supports --auto-correct.
58
- # Configuration parameters: SkipBlocks, EnforcedStyle.
59
- # SupportedStyles: described_class, explicit
60
- RSpec/DescribedClass:
61
- Exclude:
62
- - 'spec/classes/settings_spec.rb'
63
-
64
- # Offense count: 16
65
- # Cop supports --auto-correct.
66
- # Configuration parameters: AllowConsecutiveOneLiners.
67
- RSpec/EmptyLineAfterExample:
68
- Exclude:
69
- - 'spec/classes/document_spec.rb'
70
- - 'spec/classes/dry_spec.rb'
71
- - 'spec/classes/month_spec.rb'
72
- - 'spec/classes/settings_spec.rb'
73
- - 'spec/classes/verbose_spec.rb'
74
-
75
- # Offense count: 2
76
- # Cop supports --auto-correct.
77
- RSpec/EmptyLineAfterFinalLet:
78
- Exclude:
79
- - 'spec/classes/pdf_handler_spec.rb'
80
- - 'spec/classes/settings_spec.rb'
81
-
82
- # Offense count: 1
83
- # Configuration parameters: Max.
36
+ # Configuration parameters: CountAsOne.
84
37
  RSpec/ExampleLength:
85
- Exclude:
86
- - 'spec/pdfh_spec.rb'
38
+ Max: 7
87
39
 
88
- # Offense count: 1
89
- RSpec/ExpectInHook:
90
- Exclude:
91
- - 'spec/pdfh_spec.rb'
92
-
93
- # Offense count: 6
94
- # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
95
- # Include: **/*_spec*rb*, **/spec/**/*
96
- RSpec/FilePath:
97
- Exclude:
98
- - 'spec/classes/document_spec.rb'
99
- - 'spec/classes/dry_spec.rb'
100
- - 'spec/classes/month_spec.rb'
101
- - 'spec/classes/pdf_handler_spec.rb'
102
- - 'spec/classes/settings_spec.rb'
103
- - 'spec/classes/verbose_spec.rb'
104
-
105
- # Offense count: 3
106
- # Cop supports --auto-correct.
107
- RSpec/LeadingSubject:
108
- Exclude:
109
- - 'spec/classes/document_spec.rb'
110
- - 'spec/classes/pdf_handler_spec.rb'
111
- - 'spec/classes/settings_spec.rb'
112
-
113
- # Offense count: 18
114
- # Configuration parameters: .
115
- # SupportedStyles: have_received, receive
116
- RSpec/MessageSpies:
117
- EnforcedStyle: receive
118
-
119
- # Offense count: 15
40
+ # Offense count: 2
120
41
  RSpec/MultipleExpectations:
121
- Max: 4
122
-
123
- # Offense count: 71
124
- # Configuration parameters: IgnoreSharedExamples.
125
- RSpec/NamedSubject:
126
- Exclude:
127
- - 'spec/classes/document_spec.rb'
128
- - 'spec/classes/month_spec.rb'
129
- - 'spec/classes/pdf_handler_spec.rb'
130
- - 'spec/classes/settings_spec.rb'
131
- - 'spec/pdfh_spec.rb'
132
-
133
- # Offense count: 16
134
- RSpec/StubbedMock:
135
- Exclude:
136
- - 'spec/classes/document_spec.rb'
137
- - 'spec/classes/pdf_handler_spec.rb'
138
- - 'spec/pdfh_spec.rb'
42
+ Max: 2
139
43
 
140
- # Offense count: 7
44
+ # Offense count: 1
141
45
  RSpec/SubjectStub:
142
46
  Exclude:
143
- - 'spec/classes/document_spec.rb'
144
- - 'spec/classes/pdf_handler_spec.rb'
145
- - 'spec/pdfh_spec.rb'
146
-
147
- # Offense count: 4
148
- # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
149
- RSpec/VerifiedDoubles:
150
- Exclude:
151
- - 'spec/classes/document_spec.rb'
152
- - 'spec/pdfh_spec.rb'
47
+ - 'spec/pdfh/document_processor_spec.rb'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-3.0.0
1
+ 3.1.2
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.1.2
data/CHANGELOG.md CHANGED
@@ -1,16 +1,31 @@
1
+ ## v3.0.0
2
+ * Migrate to `asdf` from `rvm`
3
+ * Upgrade old gems
4
+ * Bump to v3 (as this is project's the third iteration)
5
+
6
+ ## 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
11
+ ```bash
12
+ pdfh -t document_type_id path/to_files.pdf
13
+ ```
14
+ * Add `settings.yml` template in order to create a sample file
15
+
1
16
  ## v0.1.9
2
- * Add dependencies validation at run
17
+ * Add dependencies validation at run
3
18
 
4
19
  ## v0.1.5
5
- * Add print_cmd field in config file for information purposes
6
- * Settings now validates a no existing directory
7
- * Refactor for easier maintenance
20
+ * Add `print_cmd` field in config file for information purposes
21
+ * Settings now validates an unexisting directory
22
+ * Refactor for easier maintenance
8
23
 
9
24
  ## v0.1.4
10
- * Add titleize format when writing new file
25
+ * Add titleize format when writing new file
11
26
 
12
27
  ## v0.1.3
13
- * Fixed copy companion files, which was not copying the files.
28
+ * Fixed copy companion files, which was not copying the files.
14
29
 
15
30
  ## v0.1.2
16
- * Initial Release
31
+ * Initial Release
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  gem "bundler", "~> 2.0"
9
+ gem "code-scanning-rubocop", "~> 0.5"
9
10
  gem "pry", "~> 0.14"
10
11
  gem "rake", "~> 13.0"
11
12
  gem "rspec", "~> 3.9"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pdfh (0.1.9)
4
+ pdfh (3.0.0)
5
5
  colorize (~> 0.8.0)
6
6
 
7
7
  GEM
@@ -10,55 +10,58 @@ GEM
10
10
  ansi (1.5.0)
11
11
  ast (2.4.2)
12
12
  blockenspiel (0.5.0)
13
+ code-scanning-rubocop (0.6.1)
14
+ rubocop (~> 1.0)
13
15
  coderay (1.1.3)
14
16
  colorize (0.8.1)
15
- diff-lcs (1.4.4)
16
- docile (1.3.5)
17
+ diff-lcs (1.5.0)
18
+ docile (1.4.0)
19
+ json (2.6.2)
17
20
  method_source (1.0.0)
18
- parallel (1.20.1)
19
- parser (3.0.0.0)
21
+ parallel (1.22.1)
22
+ parser (3.1.2.0)
20
23
  ast (~> 2.4.1)
21
- pry (0.14.0)
24
+ pry (0.14.1)
22
25
  coderay (~> 1.1)
23
26
  method_source (~> 1.0)
24
- rainbow (3.0.0)
25
- rake (13.0.3)
26
- regexp_parser (2.1.1)
27
- rexml (3.2.4)
28
- rspec (3.10.0)
29
- rspec-core (~> 3.10.0)
30
- rspec-expectations (~> 3.10.0)
31
- rspec-mocks (~> 3.10.0)
32
- rspec-core (3.10.1)
33
- rspec-support (~> 3.10.0)
34
- rspec-expectations (3.10.1)
27
+ rainbow (3.1.1)
28
+ rake (13.0.6)
29
+ regexp_parser (2.5.0)
30
+ rexml (3.2.5)
31
+ rspec (3.11.0)
32
+ rspec-core (~> 3.11.0)
33
+ rspec-expectations (~> 3.11.0)
34
+ rspec-mocks (~> 3.11.0)
35
+ rspec-core (3.11.0)
36
+ rspec-support (~> 3.11.0)
37
+ rspec-expectations (3.11.0)
35
38
  diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.10.0)
37
- rspec-mocks (3.10.2)
39
+ rspec-support (~> 3.11.0)
40
+ rspec-mocks (3.11.1)
38
41
  diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.10.0)
40
- rspec-support (3.10.2)
41
- rspec_junit_formatter (0.4.1)
42
+ rspec-support (~> 3.11.0)
43
+ rspec-support (3.11.0)
44
+ rspec_junit_formatter (0.5.1)
42
45
  rspec-core (>= 2, < 4, != 2.12.0)
43
- rubocop (1.11.0)
46
+ rubocop (1.32.0)
47
+ json (~> 2.3)
44
48
  parallel (~> 1.10)
45
- parser (>= 3.0.0.0)
49
+ parser (>= 3.1.0.0)
46
50
  rainbow (>= 2.2.2, < 4.0)
47
51
  regexp_parser (>= 1.8, < 3.0)
48
- rexml
49
- rubocop-ast (>= 1.2.0, < 2.0)
52
+ rexml (>= 3.2.5, < 4.0)
53
+ rubocop-ast (>= 1.19.1, < 2.0)
50
54
  ruby-progressbar (~> 1.7)
51
55
  unicode-display_width (>= 1.4.0, < 3.0)
52
- rubocop-ast (1.4.1)
53
- parser (>= 2.7.1.5)
54
- rubocop-performance (1.10.1)
55
- rubocop (>= 0.90.0, < 2.0)
56
+ rubocop-ast (1.19.1)
57
+ parser (>= 3.1.1.0)
58
+ rubocop-performance (1.14.3)
59
+ rubocop (>= 1.7.0, < 2.0)
56
60
  rubocop-ast (>= 0.4.0)
57
- rubocop-rake (0.5.1)
58
- rubocop
59
- rubocop-rspec (2.2.0)
61
+ rubocop-rake (0.6.0)
60
62
  rubocop (~> 1.0)
61
- rubocop-ast (>= 1.1.0)
63
+ rubocop-rspec (2.12.1)
64
+ rubocop (~> 1.31)
62
65
  ruby-progressbar (1.11.0)
63
66
  simplecov (0.21.2)
64
67
  docile (~> 1.1)
@@ -69,10 +72,10 @@ GEM
69
72
  simplecov
70
73
  terminal-table
71
74
  simplecov-html (0.12.3)
72
- simplecov_json_formatter (0.1.2)
73
- terminal-table (3.0.0)
74
- unicode-display_width (~> 1.1, >= 1.1.1)
75
- unicode-display_width (1.7.0)
75
+ simplecov_json_formatter (0.1.4)
76
+ terminal-table (3.0.2)
77
+ unicode-display_width (>= 1.1.1, < 3)
78
+ unicode-display_width (2.2.0)
76
79
  versionomy (0.5.0)
77
80
  blockenspiel (~> 0.5)
78
81
 
@@ -81,6 +84,7 @@ PLATFORMS
81
84
 
82
85
  DEPENDENCIES
83
86
  bundler (~> 2.0)
87
+ code-scanning-rubocop (~> 0.5)
84
88
  pdfh!
85
89
  pry (~> 0.14)
86
90
  rake (~> 13.0)
@@ -95,4 +99,4 @@ DEPENDENCIES
95
99
  versionomy (~> 0.5)
96
100
 
97
101
  BUNDLED WITH
98
- 2.2.12
102
+ 2.3.19
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
- # Pdfh
1
+ # PDF Handler (pdfh)
2
2
 
3
- Examine all PDF files in scrape directories, remove password (if has one), rename and copy to a new directory using regular expresions.
3
+ [![Rubocop](https://github.com/iax7/pdfh/actions/workflows/rubocop-analysis.yml/badge.svg)](https://github.com/iax7/pdfh/actions/workflows/rubocop-analysis.yml)
4
+ [![Ruby][ruby-badge]][ruby-url]
5
+
6
+ Examine all PDF files in Look up directories, remove password (if has one), rename and copy to a new directory using regular expresions.
4
7
 
5
8
  ## Installation
6
9
 
@@ -23,9 +26,9 @@ After installing this gem you need to create your configuration file on your hom
23
26
  `pdfh.yml`
24
27
  ```yaml
25
28
  ---
26
- scrape_dirs: # Directories where all pdf's are going to be analyzed
29
+ lookup_dirs: # Directories where all pdf's are going to be analyzed
27
30
  - ~/Downloads
28
- base_path: ~/PDFs # Directory where all matching documents will be copied
31
+ destination_base_path: ~/PDFs # Directory where all matching documents will be copied (MUST exist)
29
32
  document_types:
30
33
  - name: Document From Bank # Description
31
34
  re_file: '.*MyBankReg\.pdf' # Regular expression to match its filename
@@ -35,9 +38,22 @@ document_types:
35
38
  name_template: '{period} {subtype}' # Template for new filename when copied
36
39
  sub_types: # [OPTIONAL] In case your need an extra category
37
40
  - name: Account1 # Regular expresion to match this subtype
38
- month_offset: -1 # [OPTIONAL] Integer value to adjust month
41
+ month_offset: -1 # [OPTIONAL] Integer (signed) value to adjust month
39
42
  ```
40
43
 
44
+ Store Path supported placeholders:
45
+ * `{YEAR}` 2022
46
+
47
+ Name Template supported placeholders:
48
+
49
+ * `{original}` Original filename
50
+ * `{period}` 2022-01
51
+ * `{year}` 2022
52
+ * `{month}` 01
53
+ * `{type}` document_type.name
54
+ * `{subtype}` subtype.name if matched
55
+ * `{extra}` day if provided/matched
56
+
41
57
  ## Development
42
58
 
43
59
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -63,3 +79,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
63
79
  ## Code of Conduct
64
80
 
65
81
  Everyone interacting in the Pdfh project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/iax7/pdfh/blob/master/CODE_OF_CONDUCT.md).
82
+
83
+ <!-- Links -->
84
+ [ruby-badge]: https://img.shields.io/badge/ruby-3.1-blue?style=flat&logo=ruby&logoColor=CC342D&labelColor=white
85
+ [ruby-url]: https://www.ruby-lang.org/en/
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ task default: :spec
12
12
  desc "Bump gem version number (tiny|minor|major)"
13
13
  task :bump, :type do |_t, args|
14
14
  args.with_defaults(type: :tiny)
15
+
15
16
  version_file = File.join(__dir__, "lib", "pdfh", "version.rb")
16
17
  content = File.read(version_file)
17
18
 
@@ -22,4 +23,6 @@ task :bump, :type do |_t, args|
22
23
  File.write(version_file, content.gsub(version_pattern, "\\1#{next_version}\\3"))
23
24
 
24
25
  puts "Successfully bumped from #{current_version.to_s.red} to #{next_version.green}"
26
+ puts "\n> Building v#{next_version.green}..."
27
+ puts `rake build`
25
28
  end
data/bin/console CHANGED
@@ -9,6 +9,9 @@ require "pdfh"
9
9
 
10
10
  # (If you use this, don't forget to add pry to your Gemfile!)
11
11
  require "pry"
12
+
13
+ p Pdfh.parse_argv
14
+
12
15
  Pry.start
13
16
 
14
17
  # require "irb"
data/bin/run ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "pdfh"
6
+ require "pry"
7
+
8
+ Pdfh::DocumentProcessor.new.start
data/exe/pdfh CHANGED
@@ -1,43 +1,26 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "optparse"
4
+ require "open3"
5
5
  require "pdfh"
6
- require "pdfh/version"
7
- require "pdfh/utils"
8
6
 
9
- options = {}
10
- opt = OptionParser.new do |opts|
11
- # Process ARGV
12
- opts.banner = "Usage: #{opts.program_name} [options]"
13
- opts.on("-v", "--verbose", "Show more output, useful for debug") { |o| options[:verbose] = o }
14
- opts.on("-d", "--dry", "Dry run, does not write new pdf") { |o| options[:dry] = o }
15
- opts.on_tail("-V", "--version", "Show version") do
16
- puts "#{opts.program_name} v#{Pdfh::VERSION}"
17
- exit
7
+ # @param apps [Array]
8
+ # @return [Boolean]
9
+ def validate_installed(*apps)
10
+ found_app = []
11
+ apps.each_with_object(found_app) do |app, result|
12
+ _stdout, _stderr, status = Open3.capture3("command -v #{app}")
13
+ puts "Missing #{app} command." unless status.success?
14
+ result << status.success?
18
15
  end
19
- opts.on_tail("-h", "--help", "Show this message") do
20
- puts opts
21
- exit
22
- end
23
- end
24
16
 
25
- begin
26
- opt.parse!
27
- rescue OptionParser::InvalidOption => e
28
- Pdfh.print_error e, exit_app: false
29
- puts opt
30
- exit 1
17
+ found_app.all?
31
18
  end
32
19
 
33
- def validate_installed(app)
34
- require "open3"
35
- _stdout, _stderr, status = Open3.capture3("command -v #{app}")
36
- puts "Missing #{app} command." unless status.success?
20
+ exit(1) unless validate_installed("qpdf", "pdftotext")
37
21
 
38
- status.success?
22
+ begin
23
+ Pdfh::DocumentProcessor.new.start
24
+ rescue StandardError => e
25
+ Pdfh.error_print e.message
39
26
  end
40
-
41
- exit(1) unless validate_installed("qpdf") && validate_installed("pdftotext")
42
-
43
- Pdfh.main(options)
data/lib/ext/string.rb CHANGED
@@ -1,13 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ##
4
- # Extends String class when required
5
- module Extensions
6
- ##
7
- # Adds new functionality to string Class
8
- refine String do
9
- def titleize
10
- split.map(&:capitalize).join(" ")
11
- end
3
+ # Adds :titleize to string Class
4
+ class String
5
+ # @return [String]
6
+ def titleize
7
+ split.map(&:capitalize).join(" ")
12
8
  end
13
9
  end