ndr_import 6.4.1 → 7.0.0
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/code_safety.yml +7 -7
- data/lib/ndr_import/universal_importer_helper.rb +21 -5
- data/lib/ndr_import/version.rb +1 -1
- data/ndr_import.gemspec +1 -1
- data/test/file/pdf_test.rb +2 -1
- data/test/file/registry_test.rb +2 -1
- data/test/helpers/file/pdf_test.rb +2 -1
- data/test/universal_importer_helper_test.rb +8 -7
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a5dd34ac83682dce8b3bd5d53f3610c750e3db86defc7e6f808738d4c6a47d9
|
4
|
+
data.tar.gz: 942ca0f0d52d949c39d338938a6ab1d354f1c037675bcb8bae940c9357e672a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 370e387ead245e596ac48c4d9669e86083754e43b3d9521b20501a13569286c3820e8a699b3492121410b4de2ceada0e9c9957d3e07469afc95820f42ab3ffaa
|
7
|
+
data.tar.gz: 1e74f1eb05e132fd611250730c5f720d10930488401f07774bd12afa853dde31f22e0d1e54e3fd0d24f93a77633b8136e852932a8fc634057fda4ccba7954113
|
data/code_safety.yml
CHANGED
@@ -183,11 +183,11 @@ file safety:
|
|
183
183
|
lib/ndr_import/universal_importer_helper.rb:
|
184
184
|
comments:
|
185
185
|
reviewed_by: josh.pencheon
|
186
|
-
safe_revision:
|
186
|
+
safe_revision: 3e3a852b58e8b169535e29029e535a10f6b9cd42
|
187
187
|
lib/ndr_import/version.rb:
|
188
188
|
comments: another check?
|
189
189
|
reviewed_by: josh.pencheon
|
190
|
-
safe_revision:
|
190
|
+
safe_revision: 3f1743adb7a0ae612e480ffb9b39ba14bfb0493f
|
191
191
|
lib/ndr_import/xml/table.rb:
|
192
192
|
comments:
|
193
193
|
reviewed_by: josh.pencheon
|
@@ -195,7 +195,7 @@ file safety:
|
|
195
195
|
ndr_import.gemspec:
|
196
196
|
comments:
|
197
197
|
reviewed_by: josh.pencheon
|
198
|
-
safe_revision:
|
198
|
+
safe_revision: cb24ed3ea8116730d07f74546cd6fed0738b171d
|
199
199
|
test/file/base_test.rb:
|
200
200
|
comments:
|
201
201
|
reviewed_by: timgentry
|
@@ -215,11 +215,11 @@ file safety:
|
|
215
215
|
test/file/pdf_test.rb:
|
216
216
|
comments:
|
217
217
|
reviewed_by: josh.pencheon
|
218
|
-
safe_revision:
|
218
|
+
safe_revision: cb24ed3ea8116730d07f74546cd6fed0738b171d
|
219
219
|
test/file/registry_test.rb:
|
220
220
|
comments:
|
221
221
|
reviewed_by: josh.pencheon
|
222
|
-
safe_revision:
|
222
|
+
safe_revision: cb24ed3ea8116730d07f74546cd6fed0738b171d
|
223
223
|
test/file/text_test.rb:
|
224
224
|
comments:
|
225
225
|
reviewed_by: timgentry
|
@@ -251,7 +251,7 @@ file safety:
|
|
251
251
|
test/helpers/file/pdf_test.rb:
|
252
252
|
comments:
|
253
253
|
reviewed_by: josh.pencheon
|
254
|
-
safe_revision:
|
254
|
+
safe_revision: cb24ed3ea8116730d07f74546cd6fed0738b171d
|
255
255
|
test/helpers/file/word_test.rb:
|
256
256
|
comments:
|
257
257
|
reviewed_by: timgentry
|
@@ -471,7 +471,7 @@ file safety:
|
|
471
471
|
test/universal_importer_helper_test.rb:
|
472
472
|
comments:
|
473
473
|
reviewed_by: josh.pencheon
|
474
|
-
safe_revision:
|
474
|
+
safe_revision: 3e3a852b58e8b169535e29029e535a10f6b9cd42
|
475
475
|
test/xml/table_test.rb:
|
476
476
|
comments:
|
477
477
|
reviewed_by: josh.pencheon
|
@@ -3,6 +3,7 @@ require 'ndr_import/file/registry'
|
|
3
3
|
module NdrImport
|
4
4
|
# This mixin provides file importer helper methods that abstract away some of the
|
5
5
|
# complexity of enumerating over files and tables (which should be universally useful).
|
6
|
+
# It is assumed that the host module/class defines `unzip_path`.
|
6
7
|
module UniversalImporterHelper
|
7
8
|
def table_enumerators(filename)
|
8
9
|
table_enumerators = {}
|
@@ -23,8 +24,8 @@ module NdrImport
|
|
23
24
|
|
24
25
|
# Iterate through the file(s) line by line, yielding each one in turn, using
|
25
26
|
# get_table_mapping to select the mapping relevant to this file.
|
26
|
-
def extract(source_file,
|
27
|
-
return enum_for(:extract, source_file
|
27
|
+
def extract(source_file, &block)
|
28
|
+
return enum_for(:extract, source_file) unless block
|
28
29
|
|
29
30
|
files = NdrImport::File::Registry.files(source_file,
|
30
31
|
'unzip_path' => unzip_path)
|
@@ -47,20 +48,35 @@ module NdrImport
|
|
47
48
|
# This method does the table row yielding for the extract method, setting the notifier
|
48
49
|
# so that we can monitor progress
|
49
50
|
def yield_tables_and_their_content(filename, tables, &block)
|
51
|
+
return enum_for(:yield_tables_and_their_content, filename, tables) unless block_given?
|
52
|
+
|
50
53
|
tables.each do |tablename, table_content|
|
51
54
|
mapping = get_table_mapping(filename, tablename)
|
52
55
|
next if mapping.nil?
|
53
56
|
|
54
|
-
|
55
|
-
mapping.notifier = get_notifier(total_records)
|
57
|
+
mapping.notifier = get_notifier(record_total(filename, table_content))
|
56
58
|
|
57
59
|
yield(mapping, table_content)
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
63
|
+
def mapped_tables(filename)
|
64
|
+
@mapped_tables ||= table_enumerators(filename)
|
65
|
+
end
|
66
|
+
|
61
67
|
# This method needs to be implemented where this mixin is used.
|
62
68
|
def get_notifier(_total_records)
|
63
|
-
|
69
|
+
raise NotImplementedError, 'get_notifier must be defined!'
|
70
|
+
end
|
71
|
+
|
72
|
+
def record_total(filename, table_content)
|
73
|
+
if '.csv' == ::File.extname(filename).downcase
|
74
|
+
return `wc -l #{Shellwords.escape(filename)}`.strip.match(/\A(\d+)/)[1].to_i
|
75
|
+
elsif table_content.is_a?(Enumerator)
|
76
|
+
nil # Avoid slurping
|
77
|
+
else
|
78
|
+
table_content.size
|
79
|
+
end
|
64
80
|
end
|
65
81
|
end
|
66
82
|
end
|
data/lib/ndr_import/version.rb
CHANGED
data/ndr_import.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_dependency 'docx', '~> 0.3'
|
30
30
|
spec.add_dependency 'msworddoc-extractor', '0.2.0'
|
31
31
|
spec.add_dependency 'nokogiri', '~> 1.8', '>= 1.8.5'
|
32
|
-
spec.add_dependency 'pdf-reader', '
|
32
|
+
spec.add_dependency 'pdf-reader', '~> 2.1'
|
33
33
|
spec.add_dependency 'roo-xls'
|
34
34
|
spec.add_dependency 'spreadsheet', '1.0.3'
|
35
35
|
|
data/test/file/pdf_test.rb
CHANGED
@@ -15,7 +15,8 @@ module NdrImport
|
|
15
15
|
handler.tables.each do |tablename, sheet|
|
16
16
|
assert_nil tablename
|
17
17
|
assert_instance_of Enumerator, sheet
|
18
|
-
assert_equal ['Hello
|
18
|
+
assert_equal ['Hello World', '',
|
19
|
+
'Goodbye Universe'], sheet.to_a
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
data/test/file/registry_test.rb
CHANGED
@@ -35,7 +35,8 @@ module NdrImport
|
|
35
35
|
tables.each do |tablename, sheet|
|
36
36
|
assert_nil tablename
|
37
37
|
assert_instance_of Enumerator, sheet
|
38
|
-
assert_equal ['Hello
|
38
|
+
assert_equal ['Hello World', '',
|
39
|
+
'Goodbye Universe'], sheet.to_a
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
@@ -15,7 +15,8 @@ class PdfTest < ActiveSupport::TestCase
|
|
15
15
|
|
16
16
|
test 'read_pdf_file helper should read pdf file' do
|
17
17
|
file_content = @importer.send(:read_pdf_file, @permanent_test_files.join('hello_world.pdf'))
|
18
|
-
assert_equal ['Hello
|
18
|
+
assert_equal ['Hello World', '',
|
19
|
+
'Goodbye Universe'], file_content
|
19
20
|
end
|
20
21
|
|
21
22
|
test 'read_pdf_file helper should raise exception on invalid pdf file' do
|
@@ -17,6 +17,10 @@ class UniversalImporterHelperTest < ActiveSupport::TestCase
|
|
17
17
|
|
18
18
|
def get_notifier(_)
|
19
19
|
end
|
20
|
+
|
21
|
+
def unzip_path
|
22
|
+
SafePath.new('test_space_rw')
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
def setup
|
@@ -26,9 +30,8 @@ class UniversalImporterHelperTest < ActiveSupport::TestCase
|
|
26
30
|
|
27
31
|
test 'extract with matching mapping' do
|
28
32
|
source_file = @permanent_test_files.join('sample_xls.xls')
|
29
|
-
unzip_path = SafePath.new('test_space_rw').to_s
|
30
33
|
enumerator_ran = false
|
31
|
-
@test_importer.extract(source_file
|
34
|
+
@test_importer.extract(source_file) do |table, rows|
|
32
35
|
assert_instance_of NdrImport::Table, table
|
33
36
|
assert_instance_of Enumerator, rows
|
34
37
|
enumerator_ran = true
|
@@ -38,9 +41,8 @@ class UniversalImporterHelperTest < ActiveSupport::TestCase
|
|
38
41
|
|
39
42
|
test 'extract without matching mapping' do
|
40
43
|
source_file = @permanent_test_files.join('sample_xlsx.xlsx')
|
41
|
-
unzip_path = SafePath.new('test_space_rw').to_s
|
42
44
|
enumerator_ran = false
|
43
|
-
@test_importer.extract(source_file
|
45
|
+
@test_importer.extract(source_file) do |_table, _rows|
|
44
46
|
enumerator_ran = true
|
45
47
|
end
|
46
48
|
refute enumerator_ran
|
@@ -59,9 +61,8 @@ class UniversalImporterHelperTest < ActiveSupport::TestCase
|
|
59
61
|
{ 'column' => 'three' }])
|
60
62
|
]
|
61
63
|
source_file = @permanent_test_files.join('not_sign_delimited.txt')
|
62
|
-
unzip_path = SafePath.new('test_space_rw').to_s
|
63
64
|
@test_importer.stubs(:get_table_mapping).returns(table_mappings.first)
|
64
|
-
@test_importer.extract(source_file
|
65
|
+
@test_importer.extract(source_file) do |table, rows|
|
65
66
|
mapped_rows = table.transform(rows)
|
66
67
|
|
67
68
|
assert_instance_of NdrImport::Table, table
|
@@ -78,7 +79,7 @@ class UniversalImporterHelperTest < ActiveSupport::TestCase
|
|
78
79
|
include NdrImport::UniversalImporterHelper
|
79
80
|
end
|
80
81
|
|
81
|
-
assert_raise(
|
82
|
+
assert_raise(NotImplementedError) do
|
82
83
|
TestImporterWithoutNotifier.new.get_notifier(10_000)
|
83
84
|
end
|
84
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ndr_import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NCRS Development Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -136,16 +136,16 @@ dependencies:
|
|
136
136
|
name: pdf-reader
|
137
137
|
requirement: !ruby/object:Gem::Requirement
|
138
138
|
requirements:
|
139
|
-
- -
|
139
|
+
- - "~>"
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
141
|
+
version: '2.1'
|
142
142
|
type: :runtime
|
143
143
|
prerelease: false
|
144
144
|
version_requirements: !ruby/object:Gem::Requirement
|
145
145
|
requirements:
|
146
|
-
- -
|
146
|
+
- - "~>"
|
147
147
|
- !ruby/object:Gem::Version
|
148
|
-
version:
|
148
|
+
version: '2.1'
|
149
149
|
- !ruby/object:Gem::Dependency
|
150
150
|
name: roo-xls
|
151
151
|
requirement: !ruby/object:Gem::Requirement
|