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 +4 -4
- data/README.md +4 -0
- data/lib/smarter_csv/smarter_csv.rb +6 -6
- data/lib/smarter_csv/version.rb +1 -1
- data/spec/fixtures/ignore_comments.csv +11 -0
- data/spec/fixtures/ignore_comments2.csv +3 -0
- data/spec/smarter_csv/ignore_comments_spec.rb +30 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8862baa01aeee087fce216ba9517d301d4deb70b8cf0c8d2a2b3c7bab81c693a
|
4
|
+
data.tar.gz: bd5afb4bdcd925e5196beee967c70b60ef240a945d770554bc8b17f269c26ee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4e3080e4134aa9b59b729d4f4053426472a980d19c47d157a7175189e74f6cef6acde136f17c3be2a33e558dd9a6f85e5f7c62f35df4efffad64c9cabef2fee
|
7
|
+
data.tar.gz: 11df1ee0862b61424187c30a0edef94186b656415fccfa4182c3fba09067c11a239b89bd302c03e97d984646fa3359281572254017cdc6f45c0a693e6c4d5130
|
data/README.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
module SmarterCSV
|
2
|
-
|
3
|
-
class HeaderSizeMismatch <
|
4
|
-
class IncorrectOption <
|
5
|
-
class DuplicateHeaders <
|
6
|
-
class MissingHeaders <
|
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 =>
|
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
|
}
|
data/lib/smarter_csv/version.rb
CHANGED
@@ -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
|
+
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-
|
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.
|
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
|