smarter_csv 1.0.10 → 1.0.11

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: c8d2d18557f4dbffe6711681fa15d783f6521362
4
- data.tar.gz: 1a9e8f007ccbd329d77d6f990f77e0073a66026d
3
+ metadata.gz: b8da8da62110a7342bf1607f6d971125192d79d4
4
+ data.tar.gz: f1e42ed0dba9a1cadb609044929bdea223874887
5
5
  SHA512:
6
- metadata.gz: 8450de646c3573ec1fc87001dedbbf6ef5b062fd7bf2ab7dc91ef3973821f21dda1e5a8a613f8912faae3e632b9da1d97c29a7708172784dd8c50c075c31a5a9
7
- data.tar.gz: 77b632311d95dc2e4a4bac5f7a28c6702be0c72fc6686e90c169851ae8a8ff60e962918fdbe48acf8f3d87ac323a37826f72000c59a3c8e60d08a206d65b210c
6
+ metadata.gz: 2a15724a84cb1a1985b557236dcbbc732b1afe2fac044db9002f4c4df8e178fdd875aeaf5d0f69b76478aac77b7e96cc874ae069f90e0701b0d113823f3daf24
7
+ data.tar.gz: aced7129287273dbfea183445bf448303c0aa51af159d7880cab6e51fa79b672f8a8231cf2cfbb5a864075dae42d52e036bd5fab850298f15ca54ab27764b8f8
data/README.md CHANGED
@@ -200,8 +200,12 @@ Or install it yourself as:
200
200
 
201
201
  ## Changes
202
202
 
203
+ #### 1.0.11 (2013-09-28)
204
+ * bugfix : fixed issue #18 - fixing issue with last chunk not being properly returned (thanks to Jordan Running)
205
+ * added RSpec tests
206
+
203
207
  #### 1.0.10 (2013-06-26)
204
- * bugfix : fixed issue #14 - passing options along to CSV.parse (thank to Marcos Zimmermann)
208
+ * bugfix : fixed issue #14 - passing options along to CSV.parse (thanks to Marcos Zimmermann)
205
209
 
206
210
  #### 1.0.9 (2013-06-19)
207
211
  * bugfix : fixed issue #13 with negative integers and floats not being correctly converted (thanks to Graham Wetzler)
@@ -282,6 +286,7 @@ And a special thanks to those who contributed pull requests:
282
286
  * [Félix Bellanger](https://github.com/Keeguon)
283
287
  * [Graham Wetzler](https://github.com/grahamwetzler)
284
288
  * [Marcos G. Zimmermann](https://github.com/marcosgz)
289
+ * [Jordan Running](https://github.com/jrunning)
285
290
 
286
291
 
287
292
  ## Contributing
data/Rakefile CHANGED
@@ -1,2 +1,26 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require 'rubygems'
5
+ require 'rake'
6
+
7
+ require 'rspec/core/rake_task'
8
+
9
+ desc "Run RSpec"
10
+ RSpec::Core::RakeTask.new do |t|
11
+ t.verbose = false
12
+ end
13
+
14
+ desc "Run specs for all test cases"
15
+ task :spec_all do
16
+ system "rake spec"
17
+ end
18
+
19
+ # task :spec_all do
20
+ # %w[active_record data_mapper mongoid].each do |model_adapter|
21
+ # puts "MODEL_ADAPTER = #{model_adapter}"
22
+ # system "rake spec MODEL_ADAPTER=#{model_adapter}"
23
+ # end
24
+ # end
25
+
26
+ task :default => :spec
@@ -121,7 +121,14 @@ module SmarterCSV
121
121
  end
122
122
  chunk_count += 1
123
123
  chunk = [] # initialize for next chunk of data
124
+ else
125
+
126
+ # the last chunk may contain partial data, which also needs to be returned (BUG / ISSUE-18)
127
+
128
+
124
129
  end
130
+
131
+
125
132
  # while a chunk is being filled up we don't need to do anything else here
126
133
 
127
134
  else # no chunk handling
@@ -132,6 +139,17 @@ module SmarterCSV
132
139
  end
133
140
  end
134
141
  end
142
+ # last chunk:
143
+ if ! chunk.nil? && chunk.size > 0
144
+ # do something with the chunk
145
+ if block_given?
146
+ yield chunk # do something with the hashes in the chunk in the block
147
+ else
148
+ result << chunk # not sure yet, why anybody would want to do this without a block
149
+ end
150
+ chunk_count += 1
151
+ chunk = [] # initialize for next chunk of data
152
+ end
135
153
  ensure
136
154
  $/ = old_row_sep # make sure this stupid global variable is always reset to it's previous value after we're done!
137
155
  end
@@ -1,3 +1,3 @@
1
1
  module SmarterCSV
2
- VERSION = "1.0.10"
2
+ VERSION = "1.0.11"
3
3
  end
@@ -15,4 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.requirements = ['csv'] # for CSV.parse() only needed in case we have quoted fields
17
17
  gem.version = SmarterCSV::VERSION
18
+ gem.add_development_dependency "rspec"
19
+ # gem.add_development_dependency "guard-rspec"
18
20
  end
@@ -0,0 +1,7 @@
1
+ first name,last name,dogs,cats,birds,fish
2
+ Dan,McAllister,2,,,
3
+ Lucy,Laweless,,5,,
4
+ ,,,,,
5
+ Miles,O'Brian,,,,21
6
+ Nancy,Homes,2,,1,
7
+ ,,,,,
@@ -0,0 +1,10 @@
1
+ a,b,c
2
+ 1,2,3
3
+ ,,
4
+ 4,5,6
5
+ 7,8,9
6
+ ,,
7
+ 10,11,12
8
+ ,,
9
+ 13,14,15
10
+ ,,
@@ -0,0 +1,5 @@
1
+ first name,last name,dogs,cats,birds,fish
2
+ Dan,McAllister,2,,,
3
+ Lucy,Laweless,,5,,
4
+ Miles,O'Brian,,,,21
5
+ Nancy,Homes,2,,1,
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ fixture_path = 'spec/fixtures'
4
+
5
+ describe 'be_able_to' do
6
+ it 'loads_chunk_cornercase_csv_files' do
7
+ (0..5).each do |chunk_size| # test for all chunk-sizes
8
+ options = {:chunk_size => chunk_size, :remove_empty_hashes => true}
9
+ data = SmarterCSV.process("#{fixture_path}/chunk_cornercase.csv", options)
10
+ data.flatten.size.should == 5 # end-result must always be 5 rows
11
+ end
12
+
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ fixture_path = 'spec/fixtures'
4
+
5
+ describe 'be_able_to' do
6
+ it 'loads_basic_csv_file' do
7
+ data = SmarterCSV.process("#{fixture_path}/basic.csv")
8
+ data.size.should == 4
9
+ data.each do |h|
10
+ h.size.should <= 6
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,2 @@
1
+ --color
2
+ --backtrace
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ Bundler.require(:default)
5
+
6
+ require 'smarter_csv'
7
+
8
+
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.filter_run :focus => true
12
+ config.run_all_when_everything_filtered = true
13
+ # config.fixture_path = 'spec/fixtures'
14
+
15
+ # config.mock_with :rr
16
+ # config.before(:each) do
17
+ # Project.delete_all
18
+ # Category.delete_all
19
+ # end
20
+ end
21
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smarter_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - |
@@ -11,9 +11,19 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2013-06-26 00:00:00 Z
15
- dependencies: []
16
-
14
+ date: 2013-09-28 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - &id002
22
+ - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :development
26
+ version_requirements: *id001
17
27
  description: Ruby Gem for smarter importing of CSV Files as Array(s) of Hashes, with optional features for processing large files in parallel, embedded comments, unusual field- and record-separators, flexible mapping of CSV-headers to Hash-keys
18
28
  email:
19
29
  - |
@@ -37,6 +47,14 @@ files:
37
47
  - lib/smarter_csv/smarter_csv.rb
38
48
  - lib/smarter_csv/version.rb
39
49
  - smarter_csv.gemspec
50
+ - spec/fixtures/basic.csv
51
+ - spec/fixtures/chunk_cornercase.csv
52
+ - spec/fixtures/pets.csv
53
+ - spec/smarter_csv/chunked_reading.rb
54
+ - spec/smarter_csv/load_basic_spec.rb
55
+ - spec/spec.opts
56
+ - spec/spec/spec_helper.rb
57
+ - spec/spec_helper.rb
40
58
  homepage: https://github.com/tilo/smarter_csv
41
59
  licenses: []
42
60
 
@@ -49,13 +67,10 @@ require_paths:
49
67
  - lib
50
68
  required_ruby_version: !ruby/object:Gem::Requirement
51
69
  requirements:
52
- - &id001
53
- - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
70
+ - *id002
56
71
  required_rubygems_version: !ruby/object:Gem::Requirement
57
72
  requirements:
58
- - *id001
73
+ - *id002
59
74
  requirements:
60
75
  - csv
61
76
  rubyforge_project:
@@ -63,5 +78,12 @@ rubygems_version: 2.0.3
63
78
  signing_key:
64
79
  specification_version: 4
65
80
  summary: Ruby Gem for smarter importing of CSV Files (and CSV-like files), with lots of optional features, e.g. chunked processing for huge CSV files
66
- test_files: []
67
-
81
+ test_files:
82
+ - spec/fixtures/basic.csv
83
+ - spec/fixtures/chunk_cornercase.csv
84
+ - spec/fixtures/pets.csv
85
+ - spec/smarter_csv/chunked_reading.rb
86
+ - spec/smarter_csv/load_basic_spec.rb
87
+ - spec/spec.opts
88
+ - spec/spec/spec_helper.rb
89
+ - spec/spec_helper.rb