iron-import 0.8.0 → 0.8.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: 87cd90d663132748c61dfaa450449136f0cc00c4
4
- data.tar.gz: e350419e3bdc6afb98b6a84b4fef8c9a4f1cd4be
3
+ metadata.gz: af5ddfc35604cb25d28377798c3ea609ca7e575e
4
+ data.tar.gz: 76a6ed3cc099d49e6a5fa888b3a37dff26e2bee8
5
5
  SHA512:
6
- metadata.gz: 1646f83be5af42715b1f71f9090aa0bf323bf9495d97d4abbb5543f85cb98f006fe9bd407823810c343e3dbc81a477da1445f399bcad9eca79108fd2869719f5
7
- data.tar.gz: ba01474f1f4eebf7eaf2a23bc12824d0d57c00de61226ede66e1f1c9bd554d57161b8d811aeb2793cedc42f5a4b0bf8e9d34961c98f755aee5f09cfef1b81847
6
+ metadata.gz: d8d0f3a7cd1a6a2503df394b94dd74630d1226e4c1b0ed43fe9d76d0f264df358641ce7be2d51f30b7c0d870118af109f7e183de37e7a8d3a0c4d3aea8cd68b7
7
+ data.tar.gz: 3d6d629a0c09ce84b526025d945b55d0f4c6b8e250b3053b43ddb5fdba91e62e7c13a623f66c65a2e39700dd632464471309a6c3357b04c5e7e45c4b757a69ba
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.8.1 / 2017-07-18
2
+ * Do not include optional headers in #missing_headers
3
+ * Improve string parsing to strip trailing '.0' from incoming float values
4
+ * Add #to_h to Row for consistency with Column
5
+ * Bugfix for calls to #add_error with invalid calling signature
6
+
1
7
  == 0.8.0 / 2017-06-29
2
8
  * Breaking Change: change signature of Importer#add_error to support new features
3
9
  * Breaking Change: Importer.missing_headers will be [] instead of nil on all headers found
data/README.rdoc CHANGED
@@ -55,7 +55,7 @@ any errors encountered... well, this is the library for you!
55
55
  # order and the starting row of the data.
56
56
  importer = Importer.build do
57
57
  column :name do
58
- # Column order and start row are auto-detected
58
+ # Provide a regex to find the header for this column
59
59
  header /(name|product)/i
60
60
  end
61
61
  column :description do
data/Version.txt CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.8.1
@@ -161,7 +161,8 @@ class Importer
161
161
 
162
162
  elsif path_or_stream.is_a?(String)
163
163
  # Assume it's a path
164
- if File.exist?(path_or_stream)
164
+ is_path = File.exist?(path_or_stream) rescue false
165
+ if is_path
165
166
  if supports_file?
166
167
  # We're all set, load up the given path
167
168
  load_each(:file, path_or_stream, scopes, &block)
@@ -171,7 +172,7 @@ class Importer
171
172
  load_each(:stream, file, scopes, &block)
172
173
  end
173
174
  else
174
- add_error("Unable to locate source file #{path_or_stream}")
175
+ add_error("Unable to locate source file with path #{path_or_stream.slice(0,200)}")
175
176
  end
176
177
 
177
178
  else
@@ -219,7 +220,11 @@ class Importer
219
220
 
220
221
  case type
221
222
  when :string then
222
- val = val.to_s.strip
223
+ if val.is_a?(Float)
224
+ val.to_s.strip.gsub(/\.0+$/, '')
225
+ else
226
+ val.to_s.strip
227
+ end
223
228
 
224
229
  when :integer, :int then
225
230
  if val.class < Numeric
@@ -343,7 +343,7 @@ class Importer
343
343
  else
344
344
  # Auto select
345
345
  @reader = DataReader::for_source(self, path_or_stream)
346
- @format = @reader.format
346
+ @format = @reader.format if @reader
347
347
  end
348
348
 
349
349
  # Verify we got one
@@ -423,7 +423,7 @@ class Importer
423
423
  begin
424
424
  yield row
425
425
  rescue Exception => e
426
- add_error(row, e.to_s)
426
+ add_error(e.to_s, :row => row)
427
427
  end
428
428
  end
429
429
  end
@@ -488,7 +488,7 @@ class Importer
488
488
 
489
489
  else
490
490
  # Match by testing
491
- missing = nil
491
+ missing = []
492
492
  raw_rows.each_with_index do |row, i|
493
493
  # Um, have data?
494
494
  next unless row
@@ -496,7 +496,7 @@ class Importer
496
496
  # Set up for this iteration
497
497
  remaining = @columns.select {|c| !c.virtual? }
498
498
 
499
- # Step through this row's raw values, and look for a matching column for all columns
499
+ # Step through this row's raw values, and look for a matching header for all columns
500
500
  row.each_with_index do |val, i|
501
501
  val = val.to_s
502
502
  col = remaining.detect {|c| c.match_header?(val, i) }
@@ -532,7 +532,9 @@ class Importer
532
532
  @missing_headers = []
533
533
  return true
534
534
  else
535
- missing = remaining if (missing.nil? || missing.count > remaining.count)
535
+ # Didn't find 'em all, remember this set of missing ones for reporting later
536
+ remaining.select! {|col| !col.optional? }
537
+ missing = remaining if missing.empty? || missing.count > remaining.count
536
538
  end
537
539
  end
538
540
 
@@ -52,12 +52,13 @@ class Importer
52
52
  end
53
53
 
54
54
  # This row's values as a hash of :column_key => <parsed + validated value>
55
- def to_hash
55
+ def to_h
56
56
  @values.dup
57
57
  end
58
+ def to_hash ; to_h ; end
58
59
 
59
60
  def add_error(msg)
60
- @importer.add_error(self, msg)
61
+ @importer.add_error(msg, :row => self)
61
62
  end
62
63
 
63
64
  def has_errors?
@@ -10,7 +10,10 @@ describe Importer::DataReader do
10
10
  '1234' => 1234,
11
11
  '-2' => -2,
12
12
  '5.00' => 5,
13
+ '2.5.00' => nil,
13
14
  'foo' => nil,
15
+ '4 ducks' => nil,
16
+ '2-4' => nil,
14
17
  '' => nil,
15
18
  55 => 55,
16
19
  3.0 => 3
@@ -22,6 +25,7 @@ describe Importer::DataReader do
22
25
  it 'should parse floats' do
23
26
  {
24
27
  '1.256' => 1.256,
28
+ '4.22.00' => nil,
25
29
  '-20.3' => -20.3,
26
30
  '5.00' => 5.0,
27
31
  'foo' => nil,
@@ -39,7 +43,8 @@ describe Importer::DataReader do
39
43
  " spaces \t" => 'spaces',
40
44
  '' => nil,
41
45
  255 => '255',
42
- -1.5 => '-1.5'
46
+ -1.5 => '-1.5',
47
+ 10.0 => '10'
43
48
  }.each_pair do |val, res|
44
49
  @reader.parse_value(val, :string).should === res
45
50
  end
@@ -50,6 +55,7 @@ describe Importer::DataReader do
50
55
  '$123.00' => 12300,
51
56
  '9.95' => 995,
52
57
  '5' => 500,
58
+ '04 ' => 400,
53
59
  '0.5' => 50,
54
60
  '-95' => -9500,
55
61
  52 => 5200,
@@ -77,6 +83,7 @@ describe Importer::DataReader do
77
83
  Importer::DataReader.for_format(@importer, :csv).should be_a(Importer::CsvReader)
78
84
  Importer::DataReader.for_format(@importer, :xls).should be_a(Importer::XlsReader)
79
85
  Importer::DataReader.for_format(@importer, :xlsx).should be_a(Importer::XlsxReader)
86
+ Importer::DataReader.for_format(@importer, :html).should be_a(Importer::HtmlReader)
80
87
  Importer::DataReader.for_format(@importer, :foo).should be_nil
81
88
  end
82
89
 
@@ -84,6 +91,8 @@ describe Importer::DataReader do
84
91
  Importer::DataReader.for_path(@importer, '/tmp/foo.csv').should be_a(Importer::CsvReader)
85
92
  Importer::DataReader.for_path(@importer, 'BAR.XLS').should be_a(Importer::XlsReader)
86
93
  Importer::DataReader.for_path(@importer, '/tmp/nog_bog.xlsx').should be_a(Importer::XlsxReader)
94
+ Importer::DataReader.for_path(@importer, '/tmp/nog_bog.htm').should be_a(Importer::HtmlReader)
95
+ Importer::DataReader.for_path(@importer, '/tmp/tim.txt.html').should be_a(Importer::HtmlReader)
87
96
  Importer::DataReader.for_path(@importer, '/tmp/blinkin.bmp').should be_nil
88
97
  end
89
98
 
@@ -62,6 +62,7 @@ describe Importer do
62
62
  importer = Importer.new
63
63
  importer.column(:alpha)
64
64
  importer.column(:gamma)
65
+ importer.column(:optional, :optional => true)
65
66
  # Some dummy data
66
67
  rows = [
67
68
  ['Bob', 'Beta', 'Gamma', 'Epsilon']
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.8.0
4
+ version: 0.8.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: 2017-06-29 00:00:00.000000000 Z
11
+ date: 2017-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iron-extensions