pdfh 0.2.0 → 0.2.1
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/.ruby-version +1 -1
- data/Gemfile.lock +17 -18
- data/README.md +14 -1
- data/lib/pdfh/document.rb +7 -10
- data/lib/pdfh/document_period.rb +6 -1
- data/lib/pdfh/document_processor.rb +4 -3
- data/lib/pdfh/version.rb +1 -1
- data/lib/pdfh.rb +9 -6
- data/pdfh.gemspec +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a3761420b1befc7788493ed341094bffcf3b6f86bc2f6685f7b4de0a8201752b
|
|
4
|
+
data.tar.gz: 9da09a68dff012c3e22e67581c73b1bf874ed3abd0f9d58be8c760fa37ca6561
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5a9ba91f43fcb3e96469bf1d4499ab9e857211553bebe4732e0d3d287e4fe7946fe635b7f6e345576d69da6b07573acce2794619098d62ae40309c7f3d170f2d
|
|
7
|
+
data.tar.gz: 80a52f67d7c47159918b5cff641f5744022d1400bf71ac9fe6247814a0369e0a2ec8e2915b791a5e85e1107a28d9c64777471aa1ec448aa1ad093ecf83805287
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby-3.0
|
|
1
|
+
ruby-3.1.0
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
pdfh (0.2.
|
|
4
|
+
pdfh (0.2.1)
|
|
5
5
|
colorize (~> 0.8.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
@@ -14,18 +14,18 @@ GEM
|
|
|
14
14
|
rubocop (~> 1.0)
|
|
15
15
|
coderay (1.1.3)
|
|
16
16
|
colorize (0.8.1)
|
|
17
|
-
diff-lcs (1.
|
|
17
|
+
diff-lcs (1.5.0)
|
|
18
18
|
docile (1.4.0)
|
|
19
19
|
method_source (1.0.0)
|
|
20
|
-
parallel (1.
|
|
21
|
-
parser (3.0.
|
|
20
|
+
parallel (1.21.0)
|
|
21
|
+
parser (3.1.0.0)
|
|
22
22
|
ast (~> 2.4.1)
|
|
23
23
|
pry (0.14.1)
|
|
24
24
|
coderay (~> 1.1)
|
|
25
25
|
method_source (~> 1.0)
|
|
26
26
|
rainbow (3.0.0)
|
|
27
|
-
rake (13.0.
|
|
28
|
-
regexp_parser (2.
|
|
27
|
+
rake (13.0.6)
|
|
28
|
+
regexp_parser (2.2.0)
|
|
29
29
|
rexml (3.2.5)
|
|
30
30
|
rspec (3.10.0)
|
|
31
31
|
rspec-core (~> 3.10.0)
|
|
@@ -39,28 +39,27 @@ GEM
|
|
|
39
39
|
rspec-mocks (3.10.2)
|
|
40
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
41
41
|
rspec-support (~> 3.10.0)
|
|
42
|
-
rspec-support (3.10.
|
|
43
|
-
rspec_junit_formatter (0.
|
|
42
|
+
rspec-support (3.10.3)
|
|
43
|
+
rspec_junit_formatter (0.5.1)
|
|
44
44
|
rspec-core (>= 2, < 4, != 2.12.0)
|
|
45
|
-
rubocop (1.
|
|
45
|
+
rubocop (1.24.1)
|
|
46
46
|
parallel (~> 1.10)
|
|
47
47
|
parser (>= 3.0.0.0)
|
|
48
48
|
rainbow (>= 2.2.2, < 4.0)
|
|
49
49
|
regexp_parser (>= 1.8, < 3.0)
|
|
50
50
|
rexml
|
|
51
|
-
rubocop-ast (>= 1.
|
|
51
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
|
52
52
|
ruby-progressbar (~> 1.7)
|
|
53
53
|
unicode-display_width (>= 1.4.0, < 3.0)
|
|
54
|
-
rubocop-ast (1.
|
|
54
|
+
rubocop-ast (1.15.1)
|
|
55
55
|
parser (>= 3.0.1.1)
|
|
56
|
-
rubocop-performance (1.
|
|
56
|
+
rubocop-performance (1.13.1)
|
|
57
57
|
rubocop (>= 1.7.0, < 2.0)
|
|
58
58
|
rubocop-ast (>= 0.4.0)
|
|
59
|
-
rubocop-rake (0.
|
|
60
|
-
rubocop
|
|
61
|
-
rubocop-rspec (2.3.0)
|
|
59
|
+
rubocop-rake (0.6.0)
|
|
62
60
|
rubocop (~> 1.0)
|
|
63
|
-
|
|
61
|
+
rubocop-rspec (2.7.0)
|
|
62
|
+
rubocop (~> 1.19)
|
|
64
63
|
ruby-progressbar (1.11.0)
|
|
65
64
|
simplecov (0.21.2)
|
|
66
65
|
docile (~> 1.1)
|
|
@@ -72,9 +71,9 @@ GEM
|
|
|
72
71
|
terminal-table
|
|
73
72
|
simplecov-html (0.12.3)
|
|
74
73
|
simplecov_json_formatter (0.1.3)
|
|
75
|
-
terminal-table (3.0.
|
|
74
|
+
terminal-table (3.0.2)
|
|
76
75
|
unicode-display_width (>= 1.1.1, < 3)
|
|
77
|
-
unicode-display_width (2.
|
|
76
|
+
unicode-display_width (2.1.0)
|
|
78
77
|
versionomy (0.5.0)
|
|
79
78
|
blockenspiel (~> 0.5)
|
|
80
79
|
|
data/README.md
CHANGED
|
@@ -41,6 +41,19 @@ document_types:
|
|
|
41
41
|
month_offset: -1 # [OPTIONAL] Integer (signed) value to adjust month
|
|
42
42
|
```
|
|
43
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
|
+
|
|
44
57
|
## Development
|
|
45
58
|
|
|
46
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.
|
|
@@ -68,5 +81,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
68
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).
|
|
69
82
|
|
|
70
83
|
<!-- Links -->
|
|
71
|
-
[ruby-badge]: https://img.shields.io/badge/ruby-3.0
|
|
84
|
+
[ruby-badge]: https://img.shields.io/badge/ruby-3.1.0-blue?style=flat&logo=ruby&logoColor=CC342D&labelColor=white
|
|
72
85
|
[ruby-url]: https://www.ruby-lang.org/en/
|
data/lib/pdfh/document.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Pdfh
|
|
4
4
|
# Handles the PDF detected by the rules
|
|
5
5
|
class Document
|
|
6
|
-
attr_reader :text, :type, :file, :extra, :pdf_doc
|
|
6
|
+
attr_reader :text, :type, :file, :extra, :pdf_doc, :period
|
|
7
7
|
|
|
8
8
|
# @param file [String]
|
|
9
9
|
# @param type [DocumentType]
|
|
@@ -13,7 +13,7 @@ module Pdfh
|
|
|
13
13
|
|
|
14
14
|
@file = file
|
|
15
15
|
@type = type
|
|
16
|
-
Pdfh.verbose_print "=== Type: #{type.name} =============================="
|
|
16
|
+
Pdfh.verbose_print "=== Document Type: #{type.name} =============================="
|
|
17
17
|
@pdf_doc = PdfHandler.new(file, type.pwd)
|
|
18
18
|
@text = @pdf_doc.extract_text
|
|
19
19
|
Pdfh.verbose_print "~~~~~~~~~~~~~~~~~~ Finding a subtype"
|
|
@@ -51,17 +51,14 @@ module Pdfh
|
|
|
51
51
|
@sub_type&.name&.titleize || "N/A"
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
# @return [String]
|
|
55
|
-
def period
|
|
56
|
-
@period.to_s
|
|
57
|
-
end
|
|
58
|
-
|
|
59
54
|
# @return [String]
|
|
60
55
|
def new_name
|
|
61
56
|
template = @type.name_template
|
|
62
57
|
new_name = template
|
|
63
58
|
.sub("{original}", file_name_only)
|
|
64
|
-
.sub("{period}", period)
|
|
59
|
+
.sub("{period}", period.to_s)
|
|
60
|
+
.sub("{year}", period.year.to_s)
|
|
61
|
+
.sub("{month}", period.month.to_s)
|
|
65
62
|
.sub("{type}", type_name)
|
|
66
63
|
.sub("{subtype}", sub_type)
|
|
67
64
|
.sub("{extra}", extra || "")
|
|
@@ -70,7 +67,7 @@ module Pdfh
|
|
|
70
67
|
|
|
71
68
|
# @return [String]
|
|
72
69
|
def store_path
|
|
73
|
-
@type.store_path.gsub("{YEAR}",
|
|
70
|
+
@type.store_path.gsub("{YEAR}", period.year.to_s)
|
|
74
71
|
end
|
|
75
72
|
|
|
76
73
|
# @return [String]
|
|
@@ -103,7 +100,7 @@ module Pdfh
|
|
|
103
100
|
# unnamed matches needs to be in order month, year
|
|
104
101
|
# @return [Array] - format [month, year, day]
|
|
105
102
|
def match_data
|
|
106
|
-
Pdfh.verbose_print "~~~~~~~~~~~~~~~~~~ RegEx"
|
|
103
|
+
Pdfh.verbose_print "~~~~~~~~~~~~~~~~~~ Match Data RegEx"
|
|
107
104
|
Pdfh.verbose_print " Using regex: #{@type.re_date}"
|
|
108
105
|
Pdfh.verbose_print " named: #{@type.re_date.named_captures}"
|
|
109
106
|
matched = @type.re_date.match(@text)
|
data/lib/pdfh/document_period.rb
CHANGED
|
@@ -24,9 +24,14 @@ module Pdfh
|
|
|
24
24
|
@year = (year.size == 2 ? "20#{year}" : year).to_i + year_offset
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
# @return [String]
|
|
27
|
+
# @return [String (frozen)]
|
|
28
28
|
def to_s
|
|
29
29
|
"#{year}-#{month.to_s.rjust(2, "0")}"
|
|
30
30
|
end
|
|
31
|
+
|
|
32
|
+
# @return [String (frozen)]
|
|
33
|
+
def inspect
|
|
34
|
+
"<#{self.class} year=#{year} month=#{month}>"
|
|
35
|
+
end
|
|
31
36
|
end
|
|
32
37
|
end
|
|
@@ -11,7 +11,7 @@ module Pdfh
|
|
|
11
11
|
Pdfh.verbose = options[:verbose]
|
|
12
12
|
Pdfh.dry = options[:dry]
|
|
13
13
|
Pdfh.verbose_print(options)
|
|
14
|
-
|
|
14
|
+
Pdfh.mode = options.key?(:type) ? :file : :directory
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
# @return [void]
|
|
@@ -19,7 +19,7 @@ module Pdfh
|
|
|
19
19
|
@settings = Settings.new(Pdfh.search_config_file)
|
|
20
20
|
puts "Destination path: #{@settings.base_path.colorize(:light_blue)}" if Pdfh.verbose?
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Pdfh.file_mode? ? process_files : process_lookup_dirs
|
|
23
23
|
rescue SettingsIOError => e
|
|
24
24
|
Pdfh.error_print(e.message, exit_app: false)
|
|
25
25
|
Pdfh.create_settings_file
|
|
@@ -53,6 +53,7 @@ module Pdfh
|
|
|
53
53
|
raise ArgumentError, "No files provided to process #{type_id.inspect} type." unless options[:files]
|
|
54
54
|
|
|
55
55
|
type = doc_type_by_id(type_id)
|
|
56
|
+
Pdfh.error_print "Type #{type_id.inspect} was not found." if type.nil?
|
|
56
57
|
puts
|
|
57
58
|
options[:files].each do |file|
|
|
58
59
|
unless File.exist?(file)
|
|
@@ -109,7 +110,7 @@ module Pdfh
|
|
|
109
110
|
Pdfh.ident_print "Type", type.name, color: :light_blue, width: pad
|
|
110
111
|
doc = Document.new(file, type)
|
|
111
112
|
Pdfh.ident_print "Sub-Type", doc.sub_type, color: :light_blue, width: pad
|
|
112
|
-
Pdfh.ident_print "Period", doc.period, color: :light_blue, width: pad
|
|
113
|
+
Pdfh.ident_print "Period", doc.period.to_s, color: :light_blue, width: pad
|
|
113
114
|
Pdfh.ident_print "New Name", doc.new_name, color: :light_blue, width: pad
|
|
114
115
|
Pdfh.ident_print "Store Path", doc.store_path, color: :light_blue, width: pad
|
|
115
116
|
Pdfh.ident_print "Other files", doc.companion_files(join: true), color: :light_blue, width: pad
|
data/lib/pdfh/version.rb
CHANGED
data/lib/pdfh.rb
CHANGED
|
@@ -21,13 +21,13 @@ module Pdfh
|
|
|
21
21
|
|
|
22
22
|
# Regular Date Error, when there is not match
|
|
23
23
|
class ReDateError < StandardError
|
|
24
|
-
def initialize(msg = "
|
|
24
|
+
def initialize(msg = "Date regular expression did not find a match in document.")
|
|
25
25
|
super
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
class << self
|
|
30
|
-
attr_writer :verbose, :dry
|
|
30
|
+
attr_writer :verbose, :dry, :mode
|
|
31
31
|
|
|
32
32
|
# @return [Boolean]
|
|
33
33
|
def verbose?
|
|
@@ -39,6 +39,11 @@ module Pdfh
|
|
|
39
39
|
@dry
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
# @return [Boolean]
|
|
43
|
+
def file_mode?
|
|
44
|
+
@mode == :file
|
|
45
|
+
end
|
|
46
|
+
|
|
42
47
|
# Returns rows, cols
|
|
43
48
|
# TODO: review https://gist.github.com/nixpulvis/6025433
|
|
44
49
|
# @return [Array<Integer, Integer>]
|
|
@@ -108,9 +113,7 @@ module Pdfh
|
|
|
108
113
|
full_path = File.join(File.expand_path("~"), "#{config_file_name}.yml")
|
|
109
114
|
return if File.exist?(full_path) # double check
|
|
110
115
|
|
|
111
|
-
File.
|
|
112
|
-
f.write Pdfh::SETTINGS_TEMPLATE.to_yaml
|
|
113
|
-
end
|
|
116
|
+
File.write(full_path, Pdfh::SETTINGS_TEMPLATE.to_yaml)
|
|
114
117
|
puts "Settings #{full_path.inspect.colorize(:green)} was created."
|
|
115
118
|
end
|
|
116
119
|
|
|
@@ -128,7 +131,7 @@ module Pdfh
|
|
|
128
131
|
end
|
|
129
132
|
|
|
130
133
|
raise SettingsIOError, "no configuration file (#{names_to_look.join(" or ")}) was found\n"\
|
|
131
|
-
|
|
134
|
+
" within paths: #{dir_order.join(", ")}"
|
|
132
135
|
end
|
|
133
136
|
end
|
|
134
137
|
end
|
data/pdfh.gemspec
CHANGED
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: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
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:
|
|
11
|
+
date: 2022-01-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: colorize
|
|
@@ -70,6 +70,7 @@ metadata:
|
|
|
70
70
|
homepage_uri: https://github.com/iax7/pdfh
|
|
71
71
|
source_code_uri: https://github.com/iax7/pdfh
|
|
72
72
|
changelog_uri: https://github.com/iax7/CHANGELOG.md
|
|
73
|
+
rubygems_mfa_required: 'true'
|
|
73
74
|
post_install_message:
|
|
74
75
|
rdoc_options: []
|
|
75
76
|
require_paths:
|
|
@@ -85,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
85
86
|
- !ruby/object:Gem::Version
|
|
86
87
|
version: '0'
|
|
87
88
|
requirements: []
|
|
88
|
-
rubygems_version: 3.
|
|
89
|
+
rubygems_version: 3.3.3
|
|
89
90
|
signing_key:
|
|
90
91
|
specification_version: 4
|
|
91
92
|
summary: Organize PDF files
|