nesquikcsv 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -7
- data/ext/csv_parser/parser.c +1 -1
- data/lib/nesquikcsv/version.rb +1 -1
- data/lib/nesquikcsv.rb +13 -7
- data/test/tc_csv_parsing.rb +8 -0
- data/test/tc_interface.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3db12fc1239fab060c9570293abcf5f3460e3054
|
4
|
+
data.tar.gz: e37f17ee6cfba0c33b8ad2539dcd2194d3cf3b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21ac6172e171f974ec968d02788173b2b4ab5c1e687d38fc9e0f6e28d7873321299389f11dbf256960ddbdea8df03e5d4f0b3fc9ea8817b95ab98e3ba1be1935
|
7
|
+
data.tar.gz: 50e06a368ded7336c0232d332d12421ca89fa66cec597894fc5f96ead4013525311023cf850e63aed94ef2ba398a1d9395c9ce20cc12f8d446822a7a319ad9f3
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# NesquikCSV
|
2
2
|
|
3
|
-
Fork of the Fastest-CSV gem.
|
4
|
-
|
5
|
-
Uses native C code to parse CSV lines in MRI Ruby.
|
3
|
+
Fork of the Fastest-CSV gem to support different encodings. Uses native C code to parse CSV lines in MRI Ruby.
|
6
4
|
|
7
5
|
Supports standard CSV according to RFC4180. Not the so-called "csv" from Excel.
|
8
6
|
|
@@ -16,22 +14,25 @@ Add this line to your application's Gemfile:
|
|
16
14
|
|
17
15
|
And then execute:
|
18
16
|
|
19
|
-
|
17
|
+
bundle
|
20
18
|
|
21
19
|
Or install it yourself as:
|
22
20
|
|
23
|
-
|
21
|
+
gem install nesquikcsv
|
24
22
|
|
25
23
|
## Usage
|
26
24
|
|
27
25
|
Parse single line
|
28
26
|
|
29
|
-
|
27
|
+
# If no encoding is specified UTF-8 is assumed
|
28
|
+
NesquikCSV.parse_line "one,two,three"
|
30
29
|
=> ["one", "two", "three"]
|
30
|
+
NesquikCSV.parse_line "uno,dós,trés", "ASCII-8BIT"
|
31
|
+
=> ["uno", "d\xC3\xB3s", "tr\xC3\xA9s"]
|
31
32
|
|
32
33
|
Parse string in array of arrays
|
33
34
|
|
34
35
|
# Defaults to UTF-8
|
35
36
|
rows = NesquikCSV.parse(csv_data)
|
36
37
|
# Explicitly
|
37
|
-
rows = NesquikCSV.parse(csv_data, "UTF-8")
|
38
|
+
rows = NesquikCSV.parse(csv_data, "UTF-8")
|
data/ext/csv_parser/parser.c
CHANGED
data/lib/nesquikcsv/version.rb
CHANGED
data/lib/nesquikcsv.rb
CHANGED
@@ -89,7 +89,7 @@ class NesquikCSV
|
|
89
89
|
|
90
90
|
# Read next line from the wrapped IO and return as array or nil at EOF
|
91
91
|
def shift(encoding='UTF-8')
|
92
|
-
if line =
|
92
|
+
if line = get_line_with_quotes
|
93
93
|
CsvParser.parse_line(line, encoding)
|
94
94
|
else
|
95
95
|
nil
|
@@ -106,12 +106,18 @@ class NesquikCSV
|
|
106
106
|
def closed?
|
107
107
|
@io.closed?
|
108
108
|
end
|
109
|
-
end
|
110
109
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
def get_line_with_quotes
|
111
|
+
line = @io.gets
|
112
|
+
if !line.nil?
|
113
|
+
while line.count('"').odd?
|
114
|
+
next_line = @io.gets
|
115
|
+
break if next_line.nil?
|
116
|
+
line << next_line
|
117
|
+
end
|
118
|
+
end
|
119
|
+
line
|
115
120
|
end
|
116
|
-
end
|
117
121
|
|
122
|
+
|
123
|
+
end
|
data/test/tc_csv_parsing.rb
CHANGED
@@ -128,4 +128,12 @@ class TestCSVParsing < Test::Unit::TestCase
|
|
128
128
|
assert_equal(["ñ","ó","¸"], CsvParser.parse_line("ñ,ó,¸", "UTF-8"))
|
129
129
|
end
|
130
130
|
|
131
|
+
def test_quoted_line_break
|
132
|
+
assert_equal(["foo","bar,baz\nbeam","bee"], CsvParser.parse_line("foo,\"bar,baz\nbeam\",bee", "UTF-8"))
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_quoted_line_break_at_end
|
136
|
+
assert_equal(["foo","bar,baz\n","bee"], CsvParser.parse_line("foo,\"bar,baz\n\",bee", "UTF-8"))
|
137
|
+
end
|
138
|
+
|
131
139
|
end
|
data/test/tc_interface.rb
CHANGED
@@ -124,5 +124,18 @@ class TestNesquikCSVInterface < Test::Unit::TestCase
|
|
124
124
|
assert_equal([["1", "2", "3"], ["4", "5"]], csv.to_a)
|
125
125
|
end
|
126
126
|
end
|
127
|
+
|
128
|
+
def test_multiline
|
129
|
+
assert_equal([["foo"],["bar"]], NesquikCSV.parse("foo\nbar"))
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_quoted_line_break
|
133
|
+
assert_equal([["foo","bar,baz\nbeam","bee"],["one","two"]], NesquikCSV.parse("foo,\"bar,baz\nbeam\",bee\none,two", "UTF-8"))
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_quoted_line_break_at_end
|
137
|
+
assert_equal([[nil,"foo,\nbar,baz","beam"],["one","two"]], NesquikCSV.parse(",\"foo,\nbar,baz\",beam\none,two", "UTF-8"))
|
138
|
+
end
|
139
|
+
|
127
140
|
|
128
141
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nesquikcsv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Martty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|