csv_separator_detector 0.1.1 → 0.1.2
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/csv_separator_detector.rb +7 -1
- data/lib/csv_separator_detector/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efe669265c137cca98b90341b704c16625ed3ca3d7beb8d292ac08c208e790a7
|
4
|
+
data.tar.gz: bd75bb2d81420e2a10bd95af97b74a81c5d1c39779a802d4714c87289c25de0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1504e04ea45c89d8033fc561242dfad6758136a73608c2b8e36f55247cf4692fd3c1cf69be0f96e74011bdd15445feafa7d0c3e9a4f34ff4137bd8866673eca8
|
7
|
+
data.tar.gz: 7fb26111807484a91bf7aa37883e6a37d13440790534b659407bedc636c664f9b8d5d90c2348a5a9f659e8d89ae46486502790977d1a53ecb44ea9a76a63dfad
|
@@ -27,6 +27,7 @@ class CsvSeparatorDetector
|
|
27
27
|
# return neither of them.
|
28
28
|
def separator_with_most_columns
|
29
29
|
counts = count_columns_for_separators
|
30
|
+
return if counts.empty?
|
30
31
|
|
31
32
|
top_separators = counts.max_by(&:first).last
|
32
33
|
top_separators.first if top_separators.length == 1
|
@@ -38,9 +39,10 @@ class CsvSeparatorDetector
|
|
38
39
|
# 0 => ['\t']
|
39
40
|
# }
|
40
41
|
def count_columns_for_separators
|
42
|
+
normalized_csv_text = normalize_line_endings(csv_text)
|
41
43
|
supported_separators.each_with_object({}) do |sep, memo|
|
42
44
|
begin
|
43
|
-
columns = ::CSV.parse_line(
|
45
|
+
columns = ::CSV.parse_line(normalized_csv_text, col_sep: sep)
|
44
46
|
column_count = columns ? columns.length : 0
|
45
47
|
memo[column_count] ||= []
|
46
48
|
memo[column_count] << sep
|
@@ -49,4 +51,8 @@ class CsvSeparatorDetector
|
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
54
|
+
|
55
|
+
def normalize_line_endings(text)
|
56
|
+
text.encode(text.encoding, universal_newline: true)
|
57
|
+
end
|
52
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_separator_detector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Tulentsev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|