iron-import 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +4 -0
- data/README.rdoc +2 -2
- data/Version.txt +1 -1
- data/lib/iron/import/custom_reader.rb +7 -2
- data/lib/iron/import/data_reader.rb +8 -0
- data/lib/iron/import/sheet.rb +12 -0
- data/spec/importer/custom_reader_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e989c98b9a8dd112ec7c5926f971934e162b2017
|
4
|
+
data.tar.gz: 7d0e72179fded329171398514a215e7176879bc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59449ccc93220e21c21b8bee5dfeea71ecf91cafb52fcff0832b991c0c408e82ef7c788da988c526ec0a471426f1b05a3c0fb28bdf7648af226976d88d3f83ed
|
7
|
+
data.tar.gz: 04c84036d445c7117a0dbedff629cf2197533d533243fdaa18a82021e6258e95aeea10153357eb95da625229bbdb844a9554f4457bdd453bc1c3463095f6b5b1
|
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -7,8 +7,8 @@ Written by Rob Morris @ Irongaze Consulting LLC (http://irongaze.com)
|
|
7
7
|
Simple, reliable tabular data import.
|
8
8
|
|
9
9
|
This gem provides a set of classes to support automating import of tabular data from
|
10
|
-
CSV, XLS
|
11
|
-
order, pre-parsing data, and error/warning tracking.
|
10
|
+
CSV, XLS and XLSX files, or custom formats via a simple block reader. Provides help
|
11
|
+
in defining columns, auto-detecting column order, pre-parsing data, and error/warning tracking.
|
12
12
|
|
13
13
|
The Roo/Spreadsheet gems do a great job of providing general purpose spreadsheet reading.
|
14
14
|
However, using them with unreliable user submitted data requires a lot of error checking,
|
data/Version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.1
|
@@ -26,11 +26,16 @@ class Importer
|
|
26
26
|
|
27
27
|
def load_raw_sheet(sheet)
|
28
28
|
reader = @readers[@mode]
|
29
|
-
|
29
|
+
res = DslProxy.exec(self, @source, sheet, &reader)
|
30
|
+
if !res.is_a?(Array) || @importer.has_errors?
|
31
|
+
false
|
32
|
+
else
|
33
|
+
res
|
34
|
+
end
|
30
35
|
|
31
36
|
rescue Exception => e
|
32
37
|
# Catch any exceptions thrown and note them with helpful stacktrace info for debugging custom readers
|
33
|
-
@importer.add_error("Error in custom reader when loading
|
38
|
+
@importer.add_error("Error in custom reader when loading #{sheet}: #{e} @ #{e.backtrace.first}")
|
34
39
|
false
|
35
40
|
end
|
36
41
|
|
data/lib/iron/import/sheet.rb
CHANGED
@@ -141,6 +141,8 @@ class Importer
|
|
141
141
|
|
142
142
|
# Add a new row to our stash
|
143
143
|
def add_row(line, raw_data)
|
144
|
+
# Gracefully handle custom parsers that return nil for a row's data
|
145
|
+
raw_data ||= []
|
144
146
|
# Add the row
|
145
147
|
row = Row.new(self, line)
|
146
148
|
|
@@ -150,8 +152,10 @@ class Importer
|
|
150
152
|
index = col.data.index
|
151
153
|
raw_val = raw_data[index]
|
152
154
|
if col.parse
|
155
|
+
# Use custom parser if this row has one
|
153
156
|
val = col.parse_value(row, raw_val)
|
154
157
|
else
|
158
|
+
# Otherwise use our standard parser
|
155
159
|
val = @importer.data.parse_value(raw_val, col.type)
|
156
160
|
end
|
157
161
|
values[col.key] = val
|
@@ -236,6 +240,14 @@ class Importer
|
|
236
240
|
end
|
237
241
|
end
|
238
242
|
|
243
|
+
def add_error(msg)
|
244
|
+
@importer.add_error(self, msg)
|
245
|
+
end
|
246
|
+
|
247
|
+
def add_warning(msg)
|
248
|
+
@importer.add_warning(self, msg)
|
249
|
+
end
|
250
|
+
|
239
251
|
def to_s
|
240
252
|
"Sheet #{@id}"
|
241
253
|
end
|
@@ -43,4 +43,18 @@ describe Importer::CustomReader do
|
|
43
43
|
]
|
44
44
|
end
|
45
45
|
|
46
|
+
it 'should allow adding errors in custom blocks' do
|
47
|
+
importer = Importer.build do
|
48
|
+
headerless!
|
49
|
+
column :code
|
50
|
+
column :desc
|
51
|
+
|
52
|
+
on_file do |source, sheet|
|
53
|
+
add_error('Unable to read cause no reader')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
importer.import(SpecHelper.sample_path('icd10-custom.txt'))
|
57
|
+
importer.error_summary.should include('Unable to read cause no reader')
|
58
|
+
end
|
59
|
+
|
46
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron-import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Morris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iron-extensions
|