ndr_import 3.1.5 → 3.1.6
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 +11 -3
- data/lib/ndr_import/file/excel.rb +28 -19
- data/lib/ndr_import/version.rb +1 -1
- data/test/file/excel_test.rb +22 -3
- data/test/resources/sheet_streaming.xls +0 -0
- data/test/resources/sheet_streaming.xlsx +0 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d79b720417de07bd9f4db6de53c08600ee190ac
|
4
|
+
data.tar.gz: d267da10cc8446fe3272b6aab0e6792e6d77b3e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47a472805cd80bede14e404c026dbfdaa4a0b1f7cd1cd48f33d4c83fc27e66b0b41f91f3a64b4fdd77486f302d2ee58a0fd2c3280a9d93e128f1fc55aace7634
|
7
|
+
data.tar.gz: 515cd22f7ae8a0c2b5faa8b3d2b9f5aac08932772637bd189bfe791c3446f2daa42317a87993af8dd642969b289ef0ab880bc647a795ea9e7a9c06f89c6359ad
|
data/code_safety.yml
CHANGED
@@ -75,7 +75,7 @@ file safety:
|
|
75
75
|
lib/ndr_import/file/excel.rb:
|
76
76
|
comments:
|
77
77
|
reviewed_by: joshpencheon
|
78
|
-
safe_revision:
|
78
|
+
safe_revision: 334d53bb9e8698bba3d92b4dbd71b36faacae629
|
79
79
|
lib/ndr_import/file/pdf.rb:
|
80
80
|
comments:
|
81
81
|
reviewed_by: timgentry
|
@@ -163,7 +163,7 @@ file safety:
|
|
163
163
|
lib/ndr_import/version.rb:
|
164
164
|
comments: another check?
|
165
165
|
reviewed_by: joshpencheon
|
166
|
-
safe_revision:
|
166
|
+
safe_revision: 749aa9bb66f6e07b52acab1096f6f866034fc676
|
167
167
|
ndr_import.gemspec:
|
168
168
|
comments:
|
169
169
|
reviewed_by: josh.pencheon
|
@@ -179,7 +179,7 @@ file safety:
|
|
179
179
|
test/file/excel_test.rb:
|
180
180
|
comments:
|
181
181
|
reviewed_by: joshpencheon
|
182
|
-
safe_revision:
|
182
|
+
safe_revision: 334d53bb9e8698bba3d92b4dbd71b36faacae629
|
183
183
|
test/file/pdf_test.rb:
|
184
184
|
comments:
|
185
185
|
reviewed_by: timgentry
|
@@ -340,6 +340,14 @@ file safety:
|
|
340
340
|
comments:
|
341
341
|
reviewed_by: timgentry
|
342
342
|
safe_revision: 8c30f89f0562ab120769c166d4e93ff839c055f7
|
343
|
+
test/resources/sheet_streaming.xls:
|
344
|
+
comments:
|
345
|
+
reviewed_by: joshpencheon
|
346
|
+
safe_revision: 334d53bb9e8698bba3d92b4dbd71b36faacae629
|
347
|
+
test/resources/sheet_streaming.xlsx:
|
348
|
+
comments:
|
349
|
+
reviewed_by: joshpencheon
|
350
|
+
safe_revision: 334d53bb9e8698bba3d92b4dbd71b36faacae629
|
343
351
|
test/resources/standard_mappings.yml:
|
344
352
|
comments:
|
345
353
|
reviewed_by: timgentry
|
@@ -18,8 +18,8 @@ module NdrImport
|
|
18
18
|
return enum_for(:tables) unless block_given?
|
19
19
|
|
20
20
|
workbook = load_workbook(@filename)
|
21
|
-
workbook.
|
22
|
-
yield
|
21
|
+
workbook.sheets.each do |sheet_name|
|
22
|
+
yield sheet_name, excel_rows(workbook, sheet_name)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -49,37 +49,38 @@ module NdrImport
|
|
49
49
|
private
|
50
50
|
|
51
51
|
# Iterate through the sheet line by line, yielding each one in turn.
|
52
|
-
def excel_rows(workbook,
|
53
|
-
return enum_for(:excel_rows, workbook,
|
52
|
+
def excel_rows(workbook, sheet_name, &block)
|
53
|
+
return enum_for(:excel_rows, workbook, sheet_name) unless block
|
54
54
|
|
55
55
|
if workbook.is_a?(Roo::Excelx)
|
56
56
|
# FIXME: xlsx_rows(sheet, &block) should produce the same output as xls_rows
|
57
|
-
xls_rows(
|
57
|
+
xls_rows(workbook, sheet_name, &block)
|
58
58
|
else
|
59
|
-
xls_rows(
|
59
|
+
xls_rows(workbook, sheet_name, &block)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
# Iterate through an xls sheet line by line, yielding each one in turn.
|
64
|
-
def xls_rows(
|
65
|
-
return enum_for(:xls_rows,
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
yield line
|
64
|
+
def xls_rows(workbook, sheet_name)
|
65
|
+
return enum_for(:xls_rows, workbook, sheet_name) unless block_given?
|
66
|
+
|
67
|
+
activate_sheet!(workbook, sheet_name)
|
68
|
+
return unless workbook.first_row
|
69
|
+
(workbook.first_row..workbook.last_row).each do |row|
|
70
|
+
activate_sheet!(workbook, sheet_name)
|
71
|
+
columns = (workbook.first_column..workbook.last_column)
|
72
|
+
yield columns.map { |col| cast_excel_value(workbook.cell(row, col)) }
|
74
73
|
end
|
75
74
|
end
|
76
75
|
|
77
76
|
# Iterate through an xlsx sheet line by line, yielding each one in turn.
|
78
77
|
# This method uses streaming https://github.com/roo-rb/roo#excel-xlsx-and-xlsm-support
|
79
|
-
def xlsx_rows(
|
80
|
-
return enum_for(:xlsx_rows,
|
78
|
+
def xlsx_rows(workbook, sheet_name)
|
79
|
+
return enum_for(:xlsx_rows, workbook, sheet_name) unless block_given?
|
80
|
+
|
81
|
+
activate_sheet!(workbook, sheet_name)
|
81
82
|
|
82
|
-
|
83
|
+
workbook.each_row_streaming(:pad_cells => true) do |row|
|
83
84
|
yield row.map { |cell| cast_excel_value(cell.value) }
|
84
85
|
end
|
85
86
|
end
|
@@ -125,6 +126,14 @@ module NdrImport
|
|
125
126
|
FileUtils.mkdir_p(SafeFile.safepath_to_string(SafeFile.dirname(dest)))
|
126
127
|
FileUtils.cp(SafeFile.safepath_to_string(source), SafeFile.safepath_to_string(dest))
|
127
128
|
end
|
129
|
+
|
130
|
+
# Sets `sheet_name' to be the default (i.e. active) sheet in `workbook'.
|
131
|
+
# This setting applies to the Roo object, so needs to re-applied if (for example)
|
132
|
+
# streaming rows from multiple sheets simultaneously - something that was problematic
|
133
|
+
# with Workbook#each_with_pagename.
|
134
|
+
def activate_sheet!(workbook, sheet_name)
|
135
|
+
workbook.sheet(sheet_name)
|
136
|
+
end
|
128
137
|
end
|
129
138
|
|
130
139
|
Registry.register(Excel, 'xls', 'xlsx')
|
data/lib/ndr_import/version.rb
CHANGED
data/test/file/excel_test.rb
CHANGED
@@ -33,9 +33,28 @@ module NdrImport
|
|
33
33
|
file_path = @permanent_test_files.join('blank_tab_test.xlsx')
|
34
34
|
handler = NdrImport::File::Excel.new(file_path, nil)
|
35
35
|
|
36
|
-
handler.tables.
|
37
|
-
|
38
|
-
|
36
|
+
sheets = handler.tables.map { |_tablename, sheet| sheet }
|
37
|
+
|
38
|
+
assert_equal %w(column_a column_b column_c column_d), sheets[0].next
|
39
|
+
assert_equal %w(11111 ABC123 8888888888 2), sheets[0].next
|
40
|
+
assert_equal %w(column_a column_b column_c column_d), sheets[1].next
|
41
|
+
assert_equal %w(11111 ABC123 8888888888 3), sheets[1].next
|
42
|
+
assert_raises(StopIteration) { sheets[2].next }
|
43
|
+
end
|
44
|
+
|
45
|
+
%w(sheet_streaming.xlsx sheet_streaming.xls).each do |filename|
|
46
|
+
test "should be able to stream from multiple sheets at once from #{filename}" do
|
47
|
+
file_path = @permanent_test_files.join(filename)
|
48
|
+
handler = NdrImport::File::Excel.new(file_path, nil)
|
49
|
+
|
50
|
+
sheets = handler.tables.map { |_tablename, sheet| sheet }
|
51
|
+
|
52
|
+
assert_equal %w(1A1 1B1), sheets[0].next
|
53
|
+
assert_raises(StopIteration) { sheets[2].next }
|
54
|
+
assert_equal %w(2A1 2B1), sheets[1].next
|
55
|
+
assert_equal %w(2A2 2B2), sheets[1].next
|
56
|
+
assert_equal %w(1A2 1B2), sheets[0].next
|
57
|
+
assert_raises(StopIteration) { sheets[2].next }
|
39
58
|
end
|
40
59
|
end
|
41
60
|
|
Binary file
|
Binary file
|
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: 3.1.
|
4
|
+
version: 3.1.6
|
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: 2016-03-
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -372,6 +372,8 @@ files:
|
|
372
372
|
- test/resources/not_a_word_file.doc
|
373
373
|
- test/resources/sample_xls.xls
|
374
374
|
- test/resources/sample_xlsx.xlsx
|
375
|
+
- test/resources/sheet_streaming.xls
|
376
|
+
- test/resources/sheet_streaming.xlsx
|
375
377
|
- test/resources/standard_mappings.yml
|
376
378
|
- test/resources/txt_file_xls_extension.xls
|
377
379
|
- test/resources/txt_file_xlsx_extension.xlsx
|
@@ -453,6 +455,8 @@ test_files:
|
|
453
455
|
- test/resources/not_a_word_file.doc
|
454
456
|
- test/resources/sample_xls.xls
|
455
457
|
- test/resources/sample_xlsx.xlsx
|
458
|
+
- test/resources/sheet_streaming.xls
|
459
|
+
- test/resources/sheet_streaming.xlsx
|
456
460
|
- test/resources/standard_mappings.yml
|
457
461
|
- test/resources/txt_file_xls_extension.xls
|
458
462
|
- test/resources/txt_file_xlsx_extension.xlsx
|