hippie_csv 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hippie_csv/constants.rb +6 -1
- data/lib/hippie_csv/support.rb +5 -3
- data/lib/hippie_csv/version.rb +1 -1
- data/spec/fixtures/bad_quoting.csv +8 -0
- data/spec/hippie_csv/constants_spec.rb +2 -2
- data/spec/hippie_csv/support_spec.rb +0 -1
- data/spec/hippie_csv/version_spec.rb +1 -1
- data/spec/hippie_csv_spec.rb +11 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c3685fbff376b677274444f9b9211a80165cabd
|
4
|
+
data.tar.gz: 36322262f11c8ff9e28e90fa17ebd9be07cc9bad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d050fb4b1d7836f1167bacae1884126c92797026e1ac9177b1df316dcf146ffb34d46fc062e1a0bf5440cc9c6863fb750bc14ea76a08969a9969a90b70840b9
|
7
|
+
data.tar.gz: 24bcf0eb9c671a7116a311b74e3b381ae7557067f1e5d9174c835ac58344b5f4b0e8eaa263443d2ffd0f7b73ba7474fcb21e7c3be2b948a7d4add2507da4b14b
|
data/lib/hippie_csv/constants.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
require "csv"
|
2
2
|
|
3
3
|
module HippieCSV
|
4
|
-
QUOTE_CHARACTERS = %w(" ' |).freeze
|
4
|
+
QUOTE_CHARACTERS = %w(" ' | ∑ ⦿ ◉).freeze
|
5
|
+
# The latter three characters are not expected to intentionally used as
|
6
|
+
# quotes. Rather, when usual quote characters are badly misused, we want
|
7
|
+
# to fall back to a character _unlikely_ to be in the file, such that
|
8
|
+
# we can at least parse.
|
9
|
+
|
5
10
|
DELIMETERS = %W(, ; \t).freeze
|
6
11
|
ENCODING = "utf-8".freeze
|
7
12
|
ALTERNATE_ENCODING = "utf-16".freeze
|
data/lib/hippie_csv/support.rb
CHANGED
@@ -27,15 +27,17 @@ module HippieCSV
|
|
27
27
|
|
28
28
|
def maybe_parse(string)
|
29
29
|
QUOTE_CHARACTERS.find do |quote_character|
|
30
|
-
|
31
|
-
|
30
|
+
[string, tolerate_escaping(string, quote_character)].find do |string_to_parse|
|
31
|
+
rescuing_malformed do
|
32
|
+
return parse_csv(string_to_parse.strip, quote_character)
|
33
|
+
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
38
|
def parse_csv(string, quote_character)
|
37
39
|
CSV.parse(
|
38
|
-
|
40
|
+
string,
|
39
41
|
quote_char: quote_character,
|
40
42
|
col_sep: guess_delimeter(string, quote_character)
|
41
43
|
)
|
data/lib/hippie_csv/version.rb
CHANGED
@@ -0,0 +1,8 @@
|
|
1
|
+
id,full_name,email,support,admin_of,user_payment_count,user_payment_total,click_count,registration_date,user_status,email_validation
|
2
|
+
1,Tom Stonew,tom@example.com,Stone's Soccer Club,Stone's Soccer Club,5,£1.16,96,3/31/2015 17:28:39,active,Y
|
3
|
+
262,Mark J Collins,info@example.co,|Run N Hide Things Get Cancelled!|,Run N Hide | Things Get Cancelled!,0,NULL,0,7/2/2015 18:41:05,active,N
|
4
|
+
474,Francis Daly,francisdaly@live.com,"\A Junction\"" Project Association""",NULL,0,NULL,1,8/13/2015 14:50:05,active,N
|
5
|
+
640,mitchell miller,test@example.co.uk,Berkely ⦿ Club,NULL,0,NULL,1,9/9/2015 10:35:00,active,N
|
6
|
+
646,Ash ,hi@example.com,"\NSAAA A" """,NULL,0,NULL,0,9/9/2015 14:21:21,active,N
|
7
|
+
649,Ken Kenneth,ken@example.com,Lusk ∑ Club,Lusk ∑ Club,0,NULL,1,9/9/2015 21:45:24,active,Y
|
8
|
+
650,Bam Gouldstone,bam@example.com,$ Shave Club,NULL,0,NULL,0,9/10/2015 6:43:07,active,N
|
@@ -5,8 +5,8 @@ describe HippieCSV do
|
|
5
5
|
describe "::QUOTE_CHARACTERS" do
|
6
6
|
let(:supported_quote_characters) { ['"', "'", "|"] }
|
7
7
|
|
8
|
-
it "
|
9
|
-
expect(HippieCSV::QUOTE_CHARACTERS).to
|
8
|
+
it "supports common quote characters" do
|
9
|
+
expect(HippieCSV::QUOTE_CHARACTERS).to include(*supported_quote_characters)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "is not modifiable" do
|
@@ -68,7 +68,6 @@ describe HippieCSV::Support do
|
|
68
68
|
|
69
69
|
it "works" do
|
70
70
|
expect(subject).to receive(:guess_delimeter).with(string, quote_character).and_return(',')
|
71
|
-
expect(subject).to receive(:tolerate_escaping).with(string, quote_character).and_return(string)
|
72
71
|
|
73
72
|
expect(subject.parse_csv(string, quote_character)).to eq(
|
74
73
|
[["name", "email"], ["stephen", "test@example.com"]]
|
data/spec/hippie_csv_spec.rb
CHANGED
@@ -121,6 +121,17 @@ describe HippieCSV do
|
|
121
121
|
expect(Time.now).to be_within(5).of(start_time)
|
122
122
|
end
|
123
123
|
|
124
|
+
it "works when many invalid quote types contained" do
|
125
|
+
path = fixture_path(:bad_quoting)
|
126
|
+
|
127
|
+
expect { CSV.read(path) }.to raise_error
|
128
|
+
expect {
|
129
|
+
import = subject.read(path)
|
130
|
+
expect(import.map(&:count).uniq).to eq([11])
|
131
|
+
expect(import.count).to eq(8)
|
132
|
+
}.not_to raise_error
|
133
|
+
end
|
134
|
+
|
124
135
|
it "strips leading/trailing blank lines" do
|
125
136
|
path = fixture_path(:trailing_leading_lines)
|
126
137
|
|
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.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen O'Brien
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/hippie_csv/support.rb
|
101
101
|
- lib/hippie_csv/version.rb
|
102
102
|
- spec/fixtures/accents_semicolon_windows_1252.csv
|
103
|
+
- spec/fixtures/bad_quoting.csv
|
103
104
|
- spec/fixtures/dos_line_ending.csv
|
104
105
|
- spec/fixtures/encoding.csv
|
105
106
|
- spec/fixtures/escaped_quotes.csv
|
@@ -141,6 +142,7 @@ specification_version: 4
|
|
141
142
|
summary: Tolerant, liberal CSV parsing
|
142
143
|
test_files:
|
143
144
|
- spec/fixtures/accents_semicolon_windows_1252.csv
|
145
|
+
- spec/fixtures/bad_quoting.csv
|
144
146
|
- spec/fixtures/dos_line_ending.csv
|
145
147
|
- spec/fixtures/encoding.csv
|
146
148
|
- spec/fixtures/escaped_quotes.csv
|