pdfh 4.0.0 → 4.0.2
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/.pre-commit-config.yaml +1 -1
- data/AGENTS.md +13 -5
- data/Gemfile.lock +30 -38
- data/lib/pdfh/services/document_manager.rb +5 -3
- data/lib/pdfh/services/pdf_text_extractor.rb +1 -1
- data/lib/pdfh/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: caac169994dac2298602338729f41f79b0b047d8e5c78a8ffff3e7afe861547a
|
|
4
|
+
data.tar.gz: c1c31260ea0460b96b5cf77c103215323feaee2e7c4dfa6199962ecf1f851e16
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c817645e707161a62c42ef478e0471668547cc78f03a6e9831e060ceceb8638bd85404c7a6a929a016fc6b953d7a97c2f244350551cbec8ca6e7063054f742e
|
|
7
|
+
data.tar.gz: 444b02a1ba3324ac7ea98983d8c9500a3dafea33307f22cad5042817929db28f8be885d6fd355574014b514d1f07ae8554990d944967e51de6c69daec29a959c
|
data/.pre-commit-config.yaml
CHANGED
data/AGENTS.md
CHANGED
|
@@ -59,7 +59,11 @@ Useful `mise` tasks (`mise.toml`):
|
|
|
59
59
|
## Processing Flow (High Level)
|
|
60
60
|
|
|
61
61
|
```text
|
|
62
|
-
exe/pdfh →
|
|
62
|
+
exe/pdfh → DependencyValidator (qpdf, pdftotext) → Main.start
|
|
63
|
+
↓
|
|
64
|
+
OptParser (ARGV)
|
|
65
|
+
↓
|
|
66
|
+
SettingsBuilder → SettingsValidator
|
|
63
67
|
↓
|
|
64
68
|
DirectoryScanner.scan (finds *.pdf)
|
|
65
69
|
↓
|
|
@@ -76,9 +80,9 @@ Key service objects in `lib/pdfh/services/`:
|
|
|
76
80
|
- `PdfTextExtractor` — shells out `pdftotext -enc UTF-8 -layout`
|
|
77
81
|
- `DocumentMatcher` — iterates `DocumentType`s; matches `re_id` then `re_date`
|
|
78
82
|
- `DocumentManager` — creates dest dir, copies/renames PDF, copies companion files
|
|
79
|
-
- `SettingsBuilder` —
|
|
83
|
+
- `SettingsBuilder` — resolves config from env/known locations (`.yml`/`.yaml`), validates, and builds `Settings`
|
|
80
84
|
- `SettingsValidator` — validates settings; raises `ArgumentError` on fatal errors, warns and skips on soft errors (e.g. missing lookup dirs)
|
|
81
|
-
- `OptParser` — parses `ARGV` into `RunOptions`
|
|
85
|
+
- `OptParser` — parses `ARGV` into `RunOptions`; supports `--list-types` to print configured document type IDs
|
|
82
86
|
|
|
83
87
|
## Code Style and Conventions
|
|
84
88
|
|
|
@@ -127,6 +131,7 @@ Side effects and IO:
|
|
|
127
131
|
- File system changes are centralized in `DocumentManager`.
|
|
128
132
|
- Respect `dry_run` / `--dry` to avoid writing files.
|
|
129
133
|
- When copying/moving files, preserve metadata if possible (`FileUtils` with `preserve: true`).
|
|
134
|
+
- After successful processing, source PDFs are moved to `*.bkp` in place (`DocumentManager#backup_original`).
|
|
130
135
|
|
|
131
136
|
Testing:
|
|
132
137
|
|
|
@@ -136,7 +141,9 @@ Testing:
|
|
|
136
141
|
|
|
137
142
|
## Configuration and Templates
|
|
138
143
|
|
|
139
|
-
- Configuration is loaded from `$PDFH_CONFIG_FILE`, then CWD, `~/.config
|
|
144
|
+
- Configuration is loaded from `$PDFH_CONFIG_FILE`, then CWD, then `$XDG_CONFIG_HOME` (default `~/.config`), then `~/`.
|
|
145
|
+
- Supported config file extensions are `.yml` and `.yaml`.
|
|
146
|
+
- If no config file is found, `SettingsBuilder` creates a default template at `~/pdfh.yml`.
|
|
140
147
|
- Document templates use `{placeholder}` tokens defined in `Document#rename_data`.
|
|
141
148
|
- Date regex supports named captures `(?<m>...)` / `(?<y>...)` / `(?<d>...)` or positional captures.
|
|
142
149
|
|
|
@@ -149,7 +156,8 @@ Testing:
|
|
|
149
156
|
- **v4 breaking change**: Config format changed in v4.0.0 — old configs are incompatible. `re_id` matches PDF *text content* (not filename). New placeholders: `{day}`, `{quarter}`, `{bimester}`, `{name}`.
|
|
150
157
|
- **Multi-match behavior**: PDFs matching more than one `DocumentType` are silently skipped (see `Main.start`).
|
|
151
158
|
- **`_unlocked` suffix**: `DocumentManager` strips `_unlocked` when locating companion files — legacy pattern from `qpdf` unlocking.
|
|
152
|
-
- **
|
|
159
|
+
- **First run side effect**: Missing config does not fail fast; it auto-creates `~/pdfh.yml` and continues from that template.
|
|
160
|
+
- **Dependency mismatch risk**: `qpdf` is still checked at startup (`exe/pdfh`) even though normal v4 processing does not call it directly.
|
|
153
161
|
- **Colorize in tests**: Logging output is colored via `colorize`; specs mock `Console` with shared context `"with silent console"` to suppress output.
|
|
154
162
|
|
|
155
163
|
## Suggested Workflow for Agents
|
data/Gemfile.lock
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
pdfh (4.0.
|
|
4
|
+
pdfh (4.0.2)
|
|
5
5
|
colorize (~> 1.1.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
activesupport (8.1.
|
|
10
|
+
activesupport (8.1.3.1)
|
|
11
11
|
base64
|
|
12
12
|
bigdecimal
|
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
@@ -20,66 +20,59 @@ GEM
|
|
|
20
20
|
securerandom (>= 0.3)
|
|
21
21
|
tzinfo (~> 2.0, >= 2.0.5)
|
|
22
22
|
uri (>= 0.13.1)
|
|
23
|
-
addressable (2.8.9)
|
|
24
|
-
public_suffix (>= 2.0.2, < 8.0)
|
|
25
23
|
ast (2.4.3)
|
|
26
24
|
base64 (0.3.0)
|
|
27
|
-
bigdecimal (4.
|
|
25
|
+
bigdecimal (4.1.2)
|
|
28
26
|
code-scanning-rubocop (0.6.1)
|
|
29
27
|
rubocop (~> 1.0)
|
|
30
28
|
colorize (1.1.0)
|
|
31
|
-
concurrent-ruby (1.3.
|
|
29
|
+
concurrent-ruby (1.3.8)
|
|
32
30
|
connection_pool (3.0.2)
|
|
33
|
-
date (3.5.1)
|
|
34
31
|
debug (1.11.1)
|
|
35
32
|
irb (~> 1.10)
|
|
36
33
|
reline (>= 0.3.8)
|
|
37
34
|
diff-lcs (1.6.2)
|
|
38
35
|
docile (1.4.1)
|
|
39
36
|
drb (2.2.3)
|
|
40
|
-
erb (6.0.
|
|
41
|
-
factory_bot (6.
|
|
37
|
+
erb (6.0.6)
|
|
38
|
+
factory_bot (6.6.0)
|
|
42
39
|
activesupport (>= 6.1.0)
|
|
43
|
-
i18n (1.
|
|
40
|
+
i18n (1.15.2)
|
|
44
41
|
concurrent-ruby (~> 1.0)
|
|
45
42
|
io-console (0.8.2)
|
|
46
|
-
irb (1.
|
|
43
|
+
irb (1.18.0)
|
|
47
44
|
pp (>= 0.6.0)
|
|
48
45
|
prism (>= 1.3.0)
|
|
49
46
|
rdoc (>= 4.0.0)
|
|
50
47
|
reline (>= 0.4.2)
|
|
51
|
-
json (2.
|
|
52
|
-
|
|
53
|
-
addressable (~> 2.8)
|
|
54
|
-
bigdecimal (>= 3.1, < 5)
|
|
55
|
-
language_server-protocol (3.17.0.5)
|
|
48
|
+
json (2.21.2)
|
|
49
|
+
language_server-protocol (3.17.0.6)
|
|
56
50
|
lint_roller (1.1.0)
|
|
57
51
|
logger (1.7.0)
|
|
58
|
-
|
|
59
|
-
json-schema (>= 4.1)
|
|
60
|
-
minitest (6.0.2)
|
|
52
|
+
minitest (6.0.6)
|
|
61
53
|
drb (~> 2.0)
|
|
62
54
|
prism (~> 1.5)
|
|
63
|
-
parallel (1.
|
|
64
|
-
parser (3.3.
|
|
55
|
+
parallel (2.1.0)
|
|
56
|
+
parser (3.3.12.0)
|
|
65
57
|
ast (~> 2.4.1)
|
|
66
58
|
racc
|
|
67
|
-
pp (0.6.
|
|
59
|
+
pp (0.6.4)
|
|
68
60
|
prettyprint
|
|
69
61
|
prettyprint (0.2.0)
|
|
70
62
|
prism (1.9.0)
|
|
71
|
-
psych (5.3.1)
|
|
72
|
-
date
|
|
73
|
-
stringio
|
|
74
|
-
public_suffix (7.0.5)
|
|
75
63
|
racc (1.8.1)
|
|
76
64
|
rainbow (3.1.1)
|
|
77
|
-
rake (13.
|
|
78
|
-
|
|
65
|
+
rake (13.4.2)
|
|
66
|
+
rbs (4.1.2)
|
|
67
|
+
logger
|
|
68
|
+
prism (>= 1.6.0)
|
|
69
|
+
tsort
|
|
70
|
+
rdoc (8.0.0)
|
|
79
71
|
erb
|
|
80
|
-
|
|
72
|
+
prism (>= 1.6.0)
|
|
73
|
+
rbs (>= 4.0.0)
|
|
81
74
|
tsort
|
|
82
|
-
regexp_parser (2.
|
|
75
|
+
regexp_parser (2.12.0)
|
|
83
76
|
reline (0.6.3)
|
|
84
77
|
io-console (~> 0.5)
|
|
85
78
|
rspec (3.13.2)
|
|
@@ -95,19 +88,18 @@ GEM
|
|
|
95
88
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
96
89
|
rspec-support (~> 3.13.0)
|
|
97
90
|
rspec-support (3.13.7)
|
|
98
|
-
rubocop (1.
|
|
91
|
+
rubocop (1.88.2)
|
|
99
92
|
json (~> 2.3)
|
|
100
93
|
language_server-protocol (~> 3.17.0.2)
|
|
101
94
|
lint_roller (~> 1.1.0)
|
|
102
|
-
|
|
103
|
-
parallel (~> 1.10)
|
|
95
|
+
parallel (>= 1.10)
|
|
104
96
|
parser (>= 3.3.0.2)
|
|
105
97
|
rainbow (>= 2.2.2, < 4.0)
|
|
106
98
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
107
99
|
rubocop-ast (>= 1.49.0, < 2.0)
|
|
108
100
|
ruby-progressbar (~> 1.7)
|
|
109
101
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
110
|
-
rubocop-ast (1.
|
|
102
|
+
rubocop-ast (1.50.0)
|
|
111
103
|
parser (>= 3.3.7.2)
|
|
112
104
|
prism (~> 1.7)
|
|
113
105
|
rubocop-factory_bot (2.28.0)
|
|
@@ -120,9 +112,10 @@ GEM
|
|
|
120
112
|
rubocop-rake (0.7.1)
|
|
121
113
|
lint_roller (~> 1.1)
|
|
122
114
|
rubocop (>= 1.72.1)
|
|
123
|
-
rubocop-rspec (3.
|
|
115
|
+
rubocop-rspec (3.10.2)
|
|
124
116
|
lint_roller (~> 1.1)
|
|
125
|
-
|
|
117
|
+
regexp_parser (>= 2.0)
|
|
118
|
+
rubocop (~> 1.86, >= 1.86.2)
|
|
126
119
|
ruby-progressbar (1.13.0)
|
|
127
120
|
securerandom (0.4.1)
|
|
128
121
|
simplecov (0.22.0)
|
|
@@ -131,7 +124,6 @@ GEM
|
|
|
131
124
|
simplecov_json_formatter (~> 0.1)
|
|
132
125
|
simplecov-html (0.13.2)
|
|
133
126
|
simplecov_json_formatter (0.1.4)
|
|
134
|
-
stringio (3.2.0)
|
|
135
127
|
tsort (0.2.0)
|
|
136
128
|
tzinfo (2.0.6)
|
|
137
129
|
concurrent-ruby (~> 1.0)
|
|
@@ -159,4 +151,4 @@ DEPENDENCIES
|
|
|
159
151
|
simplecov (~> 0.22)
|
|
160
152
|
|
|
161
153
|
BUNDLED WITH
|
|
162
|
-
4.0.
|
|
154
|
+
4.0.17
|
|
@@ -89,16 +89,18 @@ module Pdfh
|
|
|
89
89
|
# Finds companion files by removing the _unlocked suffix from the PDF name if present.
|
|
90
90
|
# This allows PDFs unlock by qpdf to locate their original companion files (e.g., .xml, .txt)
|
|
91
91
|
# that were never renamed with the _unlocked suffix.
|
|
92
|
+
# Excludes PDF files and `.bkp` backup files (already-processed PDFs renamed by +backup_original+).
|
|
92
93
|
#
|
|
93
|
-
# @return [Array<String>] array of non-PDF files with the same base name
|
|
94
|
+
# @return [Array<String>] array of non-PDF, non-backup files with the same base name
|
|
94
95
|
# @example
|
|
95
96
|
# # If document is "cuenta_unlocked.pdf", searches for "cuenta.*"
|
|
96
|
-
# # Returns ["cuenta.xml", "cuenta.txt"] (excluding "cuenta.pdf")
|
|
97
|
+
# # Returns ["cuenta.xml", "cuenta.txt"] (excluding "cuenta.pdf" and "cuenta.pdf.bkp")
|
|
97
98
|
def companion_files
|
|
98
99
|
@companion_files ||= begin
|
|
99
100
|
base_name = document.file_info.stem.delete_suffix(PDF_UNLOCKED_MAGIC_SUFFIX)
|
|
100
101
|
Dir.glob(File.join(document.file_info.dir, "#{base_name}.*")).reject do |file|
|
|
101
|
-
File.extname(file)
|
|
102
|
+
ext = File.extname(file)
|
|
103
|
+
ext == ".pdf" || file.end_with?(".bkp")
|
|
102
104
|
end
|
|
103
105
|
end
|
|
104
106
|
end
|
data/lib/pdfh/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pdfh
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.0.
|
|
4
|
+
version: 4.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Isaias Piña
|
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
98
98
|
- !ruby/object:Gem::Version
|
|
99
99
|
version: '0'
|
|
100
100
|
requirements: []
|
|
101
|
-
rubygems_version: 4.0.
|
|
101
|
+
rubygems_version: 4.0.17
|
|
102
102
|
specification_version: 4
|
|
103
103
|
summary: Organize PDF files
|
|
104
104
|
test_files: []
|