hippie_csv 0.0.8 → 0.0.9

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: d09ec409677ca747265cd3542b2ca799d7d6cb78
4
- data.tar.gz: 3f6a81c389556408e7cae8dd73f5e6da70bc5593
3
+ metadata.gz: 178191d199c6e5318a8377be2852354d1371537e
4
+ data.tar.gz: cd17b3aa8028743e6b531c67ba36822d2a31a4a8
5
5
  SHA512:
6
- metadata.gz: 46c7ceaf2d3125fe02b3ba8feb8aedb4078db0eb685f109a8cb4e6f0006b008c14a4d4d74828269662023fc34a75d4e8d3a1732cac76539c848c906955a7b073
7
- data.tar.gz: 22ac0bfd0871c7c7b6c010667da643307e7bc5d4d5a12da0d9ead4134b0ec79fb8126883023a8c4b69d6dd476ffc144ff9cd65c88c06aab4caa1482e0b7360cd
6
+ metadata.gz: 86f07865e61f68ad07c4811d1fdfc7db210f476f9042d7cdac2cea2aa0da6de44c4fdb589d8fa0e35245ed90aec4c7f5df2c5dfeb98dcf7e8d458c47b9398b42
7
+ data.tar.gz: ec95093f3a6e3c060b8706b76538d050040f91a4307888e3ff2a05544fa29f0897375c6c0cdde88f8b4c91dfdf68ba83378a2aeccf7b8cbf79101c11ebc4f363
@@ -13,5 +13,4 @@ module HippieCSV
13
13
  FIELD_SAMPLE_COUNT = 10.freeze
14
14
  ENCODING_SAMPLE_CHARACTER_COUNT = 10000.freeze
15
15
  ENCODING_WITH_BOM = "bom|#{ENCODING}".freeze
16
- BLANK_LINE_REGEX = /^,+\r+$/.freeze
17
16
  end
@@ -21,7 +21,11 @@ module HippieCSV
21
21
  magical_encode(string)
22
22
  end
23
23
  end
24
- string.gsub!(BLANK_LINE_REGEX, "")
24
+
25
+ DELIMETERS.each do |delimiter|
26
+ string.gsub!(blank_line_regex(delimiter), "")
27
+ end
28
+
25
29
  string.encode(string.encoding, universal_newline: true)
26
30
  end
27
31
 
@@ -29,7 +33,7 @@ module HippieCSV
29
33
  QUOTE_CHARACTERS.find do |quote_character|
30
34
  [string, tolerate_escaping(string, quote_character)].find do |string_to_parse|
31
35
  rescuing_malformed do
32
- return parse_csv(string_to_parse.strip, quote_character)
36
+ return parse_csv(string_to_parse.squeeze("\n").strip, quote_character)
33
37
  end
34
38
  end
35
39
  end
@@ -63,6 +67,10 @@ module HippieCSV
63
67
 
64
68
  private
65
69
 
70
+ def blank_line_regex(delimiter)
71
+ /^#{delimiter}+(\r\n|\r)$/
72
+ end
73
+
66
74
  def detect_encoding(string)
67
75
  CharDet.detect(string[0..ENCODING_SAMPLE_CHARACTER_COUNT])["encoding"]
68
76
  end
@@ -1,3 +1,3 @@
1
1
  module HippieCSV
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -0,0 +1,9 @@
1
+ Email,First Name,Last Name
2
+ admin@example.com,The,Admin
3
+ ,,
4
+ msonstot@example.com,Matt, Clemens
5
+ ,,
6
+ nathan@example.com,NATHAN,O'BRIEN
7
+ ,,
8
+ ,,
9
+ garry@example.com,Garry,Redmond
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe HippieCSV do
4
4
 
5
5
  it "defines a version" do
6
- expect(HippieCSV::VERSION).to eq("0.0.8")
6
+ expect(HippieCSV::VERSION).to eq("0.0.9")
7
7
  end
8
8
 
9
9
  end
@@ -141,10 +141,12 @@ describe HippieCSV do
141
141
  end
142
142
 
143
143
  it "maintains coherent column count when stripping blank lines" do
144
- path = fixture_path(:trailing_leading_blank_lines)
144
+ [:blank_lines_crlf, :trailing_leading_blank_lines].each do |fixture_name|
145
+ path = fixture_path(fixture_name)
145
146
 
146
- import = subject.read(path)
147
- expect(import.map(&:length).uniq.size).to eq(1)
147
+ import = subject.read(path)
148
+ expect(import.map(&:length).uniq.size).to eq(1)
149
+ end
148
150
  end
149
151
  end
150
152
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hippie_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen O'Brien
@@ -101,6 +101,7 @@ files:
101
101
  - lib/hippie_csv/version.rb
102
102
  - spec/fixtures/accents_semicolon_windows_1252.csv
103
103
  - spec/fixtures/bad_quoting.csv
104
+ - spec/fixtures/blank_lines_crlf.csv
104
105
  - spec/fixtures/dos_line_ending.csv
105
106
  - spec/fixtures/encoding.csv
106
107
  - spec/fixtures/escaped_quotes.csv
@@ -143,6 +144,7 @@ summary: Tolerant, liberal CSV parsing
143
144
  test_files:
144
145
  - spec/fixtures/accents_semicolon_windows_1252.csv
145
146
  - spec/fixtures/bad_quoting.csv
147
+ - spec/fixtures/blank_lines_crlf.csv
146
148
  - spec/fixtures/dos_line_ending.csv
147
149
  - spec/fixtures/encoding.csv
148
150
  - spec/fixtures/escaped_quotes.csv