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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04d666ea1e0170b0186d75fc8b0ec367a16e528a
4
- data.tar.gz: 9dad576e17b7d8fc4b523ffe6b4e53c85feae9c8
3
+ metadata.gz: e989c98b9a8dd112ec7c5926f971934e162b2017
4
+ data.tar.gz: 7d0e72179fded329171398514a215e7176879bc0
5
5
  SHA512:
6
- metadata.gz: e5a31e81381d78c29da480b296a8e9569ed415a32f50610881014de52a7b92c925687d3ee4ba683bf64a50562b26bf5785acf09070017710938d39c52f0087ad
7
- data.tar.gz: d29901644886a98c617dd215b52edec0e8c011875ae2c0d6724c8f0f03c26bfdb9ea8028a3322c9cf1d16f91d9010950203c73ff0fc0485ce0bfc09ffc53e6f2
6
+ metadata.gz: 59449ccc93220e21c21b8bee5dfeea71ecf91cafb52fcff0832b991c0c408e82ef7c788da988c526ec0a471426f1b05a3c0fb28bdf7648af226976d88d3f83ed
7
+ data.tar.gz: 04c84036d445c7117a0dbedff629cf2197533d533243fdaa18a82021e6258e95aeea10153357eb95da625229bbdb844a9554f4457bdd453bc1c3463095f6b5b1
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.6.1 / 2015-08-24
2
+
3
+ * Better handling for nil return value in custom format readers
4
+
1
5
  == 0.6.0 / 2015-08-17
2
6
 
3
7
  * Refactored readers to allow for custom format reading
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 or XLSX files. Provides help in defining columns, auto-detecting column
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.0
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
- reader.call(@source, sheet)
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 sheet #{sheet}: #{e} @ #{e.backtrace.first}")
38
+ @importer.add_error("Error in custom reader when loading #{sheet}: #{e} @ #{e.backtrace.first}")
34
39
  false
35
40
  end
36
41
 
@@ -257,6 +257,14 @@ class Importer
257
257
  end
258
258
  end
259
259
 
260
+ def add_error(*args)
261
+ @importer.add_error(*args)
262
+ end
263
+
264
+ def add_warning(*args)
265
+ @importer.add_warning(*args)
266
+ end
267
+
260
268
  end
261
269
 
262
270
  end
@@ -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.0
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-18 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iron-extensions