smarter_csv 1.2.4 → 1.2.5

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
  SHA256:
3
- metadata.gz: b12b00d4615d3c9c6bb3f233b5179b8a3990204af46c88b6ee2203de307608e0
4
- data.tar.gz: 215dc43d5280083f7452c0be169daab991057239601fa37c23cd474649a8cd4d
3
+ metadata.gz: 8862baa01aeee087fce216ba9517d301d4deb70b8cf0c8d2a2b3c7bab81c693a
4
+ data.tar.gz: bd5afb4bdcd925e5196beee967c70b60ef240a945d770554bc8b17f269c26ee4
5
5
  SHA512:
6
- metadata.gz: 05bc8348e29d095788ee6d2a9cf299232fc1e7f8abc5048544e80a0f0c6b5d7517b935daddc3eb697a5f01616eb5a3dd2a9b4d0ee489f358e0b95718caba243f
7
- data.tar.gz: bd2b070f965ba554b2b2551a5959690308a1a68fdbe452b6d7900e7c665202e73e1b1bfba0b4d4da72324490c55e8fd869497df64e959b80706af63509a4b1fd
6
+ metadata.gz: f4e3080e4134aa9b59b729d4f4053426472a980d19c47d157a7175189e74f6cef6acde136f17c3be2a33e558dd9a6f85e5f7c62f35df4efffad64c9cabef2fee
7
+ data.tar.gz: 11df1ee0862b61424187c30a0edef94186b656415fccfa4182c3fba09067c11a239b89bd302c03e97d984646fa3359281572254017cdc6f45c0a693e6c4d5130
data/README.md CHANGED
@@ -324,6 +324,10 @@ Planned in the next releases:
324
324
 
325
325
  ## Changes
326
326
 
327
+ #### 1.2.5 (2018-09-16)
328
+ * fixing issue #136 with comments in CSV files
329
+ * fixing error class hierarchy
330
+
327
331
  #### 1.2.4 (2018-08-06)
328
332
  * using Rails blank? if it's available
329
333
 
@@ -1,16 +1,16 @@
1
1
  module SmarterCSV
2
-
3
- class HeaderSizeMismatch < Exception; end
4
- class IncorrectOption < Exception; end
5
- class DuplicateHeaders < Exception; end
6
- class MissingHeaders < Exception; end
2
+ class SmarterCSVException < StandardError; end
3
+ class HeaderSizeMismatch < SmarterCSVException; end
4
+ class IncorrectOption < SmarterCSVException; end
5
+ class DuplicateHeaders < SmarterCSVException; end
6
+ class MissingHeaders < SmarterCSVException; end
7
7
 
8
8
 
9
9
  def SmarterCSV.process(input, options={}, &block) # first parameter: filename or input object with readline method
10
10
  default_options = {:col_sep => ',' , :row_sep => $/ , :quote_char => '"', :force_simple_split => false , :verbose => false ,
11
11
  :remove_empty_values => true, :remove_zero_values => false , :remove_values_matching => nil , :remove_empty_hashes => true , :strip_whitespace => true,
12
12
  :convert_values_to_numeric => true, :strip_chars_from_headers => nil , :user_provided_headers => nil , :headers_in_file => true,
13
- :comment_regexp => /^#/, :chunk_size => nil , :key_mapping_hash => nil , :downcase_header => true, :strings_as_keys => false, :file_encoding => 'utf-8',
13
+ :comment_regexp => /\A#/, :chunk_size => nil , :key_mapping_hash => nil , :downcase_header => true, :strings_as_keys => false, :file_encoding => 'utf-8',
14
14
  :remove_unmapped_keys => false, :keep_original_headers => false, :value_converters => nil, :skip_lines => nil, :force_utf8 => false, :invalid_byte_sequence => '',
15
15
  :auto_row_sep_chars => 500, :required_headers => nil
16
16
  }
@@ -1,3 +1,3 @@
1
1
  module SmarterCSV
2
- VERSION = "1.2.4"
2
+ VERSION = "1.2.5"
3
3
  end
@@ -0,0 +1,11 @@
1
+ not a comment#First Name,Last Name,Dogs,Cats,Birds,Fish
2
+ # comment two
3
+ Dan,McAllister,2,0,,
4
+ Lucy#L,Laweless,,5,0,
5
+ # anothter comment
6
+ ,,,,,
7
+ Miles,O'Brian,0,0,0,21
8
+ Nancy,Homes,2,0,1,
9
+ Hernán,Curaçon,3,0,0,
10
+ #comment,comment,1,2,3,4
11
+ ,,,,,
@@ -0,0 +1,3 @@
1
+ h1,h2
2
+ a,"b
3
+ #c"
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ fixture_path = 'spec/fixtures'
4
+
5
+ describe 'be_able_to' do
6
+ it 'ignore comments in CSV files' do
7
+ options = {}
8
+ data = SmarterCSV.process("#{fixture_path}/ignore_comments.csv", options)
9
+
10
+ data.size.should eq 5
11
+
12
+ # all the keys should be symbols
13
+ data.each{|item| item.keys.each{|x| x.is_a?(Symbol).should be_truthy}}
14
+ data.each do |h|
15
+ h.keys.each do |key|
16
+ [:"not_a_comment#first_name", :last_name, :dogs, :cats, :birds, :fish].should include( key )
17
+ end
18
+ end
19
+ end
20
+
21
+ it 'ignore comments in CSV files with CRLF' do
22
+ options = {row_sep: "\r\n"}
23
+ data = SmarterCSV.process("#{fixture_path}/ignore_comments2.csv", options)
24
+
25
+ # all the keys should be symbols
26
+ data.size.should eq 1
27
+ data.first[:h1].should eq 'a'
28
+ data.first[:h2].should eq "b\r\n#c"
29
+ end
30
+ end
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.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'Tilo Sloboda
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-08-06 00:00:00.000000000 Z
13
+ date: 2018-09-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -58,6 +58,8 @@ files:
58
58
  - spec/fixtures/chunk_cornercase.csv
59
59
  - spec/fixtures/duplicate_headers.csv
60
60
  - spec/fixtures/empty.csv
61
+ - spec/fixtures/ignore_comments.csv
62
+ - spec/fixtures/ignore_comments2.csv
61
63
  - spec/fixtures/line_endings_n.csv
62
64
  - spec/fixtures/line_endings_r.csv
63
65
  - spec/fixtures/line_endings_rn.csv
@@ -88,6 +90,7 @@ files:
88
90
  - spec/smarter_csv/convert_values_to_numeric_spec.rb
89
91
  - spec/smarter_csv/extenstions_spec.rb
90
92
  - spec/smarter_csv/header_transformation_spec.rb
93
+ - spec/smarter_csv/ignore_comments_spec.rb
91
94
  - spec/smarter_csv/invalid_headers_spec.rb
92
95
  - spec/smarter_csv/keep_headers_spec.rb
93
96
  - spec/smarter_csv/key_mapping_spec.rb
@@ -134,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
137
  requirements:
135
138
  - csv
136
139
  rubyforge_project:
137
- rubygems_version: 2.7.4
140
+ rubygems_version: 2.7.7
138
141
  signing_key:
139
142
  specification_version: 4
140
143
  summary: Ruby Gem for smarter importing of CSV Files (and CSV-like files), with lots
@@ -149,6 +152,8 @@ test_files:
149
152
  - spec/fixtures/chunk_cornercase.csv
150
153
  - spec/fixtures/duplicate_headers.csv
151
154
  - spec/fixtures/empty.csv
155
+ - spec/fixtures/ignore_comments.csv
156
+ - spec/fixtures/ignore_comments2.csv
152
157
  - spec/fixtures/line_endings_n.csv
153
158
  - spec/fixtures/line_endings_r.csv
154
159
  - spec/fixtures/line_endings_rn.csv
@@ -179,6 +184,7 @@ test_files:
179
184
  - spec/smarter_csv/convert_values_to_numeric_spec.rb
180
185
  - spec/smarter_csv/extenstions_spec.rb
181
186
  - spec/smarter_csv/header_transformation_spec.rb
187
+ - spec/smarter_csv/ignore_comments_spec.rb
182
188
  - spec/smarter_csv/invalid_headers_spec.rb
183
189
  - spec/smarter_csv/keep_headers_spec.rb
184
190
  - spec/smarter_csv/key_mapping_spec.rb