hippie_csv 0.0.10 → 0.0.11
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/README.md +2 -2
- data/lib/hippie_csv/support.rb +15 -12
- data/lib/hippie_csv/version.rb +1 -1
- data/spec/hippie_csv/support_spec.rb +11 -0
- data/spec/hippie_csv/version_spec.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07464f9018551eea7e183ef2ffd0e855b8a46d6a
|
4
|
+
data.tar.gz: 98b28c4757768af0fe785127914bdc964a067cff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 346448b5193bc9beeddee5ec1dfe066a795d0a8820b2dbf28910925bf461feaec1cbbcd886394bf8323d47d931cbfda6e540febe5d5a51935b6fc127c0b61573
|
7
|
+
data.tar.gz: ec3278642148bc8597af5d5128fe2c9ac2231fa7b87c19dc40d3a0933ba0a41c0407464bcbe938609e3ea55c72587d39c3c50d56b04c280e4300bd8f5f27e44e
|
data/README.md
CHANGED
@@ -44,8 +44,8 @@ HippieCSV.parse(csv_string)
|
|
44
44
|
|
45
45
|
## Features
|
46
46
|
|
47
|
-
- Deduces the delimiter (supports `,`, `;`, and
|
48
|
-
- Deduces the quote character (supports `'` and
|
47
|
+
- Deduces the delimiter (supports `,`, `;`, and `\t`)
|
48
|
+
- Deduces the quote character (supports `'`, `"`, and `|`)
|
49
49
|
- Forgives backslash escaped quotes in quoted CSVs
|
50
50
|
- Forgives invalid newlines in quoted CSVs
|
51
51
|
- Heals many encoding issues (and aggressively forces UTF-8)
|
data/lib/hippie_csv/support.rb
CHANGED
@@ -9,18 +9,7 @@ module HippieCSV
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def encode(string)
|
12
|
-
|
13
|
-
string = begin
|
14
|
-
current_encoding = detect_encoding(string)
|
15
|
-
if !current_encoding.nil?
|
16
|
-
string.encode(ENCODING, current_encoding)
|
17
|
-
else
|
18
|
-
magical_encode(string)
|
19
|
-
end
|
20
|
-
rescue Encoding::InvalidByteSequenceError
|
21
|
-
magical_encode(string)
|
22
|
-
end
|
23
|
-
end
|
12
|
+
string = ensure_valid_encoding(string)
|
24
13
|
|
25
14
|
DELIMETERS.each do |delimiter|
|
26
15
|
string.gsub!(blank_line_regex(delimiter), "")
|
@@ -71,6 +60,20 @@ module HippieCSV
|
|
71
60
|
|
72
61
|
private
|
73
62
|
|
63
|
+
def ensure_valid_encoding(string)
|
64
|
+
return string if string.valid_encoding?
|
65
|
+
|
66
|
+
current_encoding = detect_encoding(string)
|
67
|
+
|
68
|
+
if !current_encoding.nil? && current_encoding != ENCODING
|
69
|
+
string.encode(ENCODING, current_encoding)
|
70
|
+
else
|
71
|
+
magical_encode(string)
|
72
|
+
end
|
73
|
+
rescue Encoding::InvalidByteSequenceError
|
74
|
+
magical_encode(string)
|
75
|
+
end
|
76
|
+
|
74
77
|
def blank_line_regex(delimiter)
|
75
78
|
/^#{delimiter}+(\r\n|\r)$/
|
76
79
|
end
|
data/lib/hippie_csv/version.rb
CHANGED
@@ -38,6 +38,17 @@ describe HippieCSV::Support do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
context "with a string detected to be UTF-8 but with an invalid byte sequence" do
|
42
|
+
let(:utf8_string) { ("Rubyのメ" * HippieCSV::ENCODING_SAMPLE_CHARACTER_COUNT).force_encoding("utf-8") }
|
43
|
+
let(:string) { utf8_string << "\xBF"}
|
44
|
+
|
45
|
+
it "ensures encoding becomes valid" do
|
46
|
+
expect(string).not_to be_valid_encoding
|
47
|
+
|
48
|
+
expect(subject.encode(string)).to be_valid_encoding
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
41
52
|
context 'with unquoted fields and \r or \n' do
|
42
53
|
let(:string) { "id,first_name,last_name\r123,Heinrich,Schütz\r\n" }
|
43
54
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen O'Brien
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.5.1
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: Tolerant, liberal CSV parsing
|
@@ -162,4 +162,3 @@ test_files:
|
|
162
162
|
- spec/hippie_csv/version_spec.rb
|
163
163
|
- spec/hippie_csv_spec.rb
|
164
164
|
- spec/spec_helper.rb
|
165
|
-
has_rdoc:
|