csv_separator_detector 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: fc6d9464377f2e0437a4f4c081ed04d78e7f39438b4c0b6348b3c7dd57a7ac49
4
- data.tar.gz: d46011965be500f4907607ec8c3c8a35a1abf50699b8b2517c65cc62becf6043
3
+ metadata.gz: efe669265c137cca98b90341b704c16625ed3ca3d7beb8d292ac08c208e790a7
4
+ data.tar.gz: bd75bb2d81420e2a10bd95af97b74a81c5d1c39779a802d4714c87289c25de0b
5
5
  SHA512:
6
- metadata.gz: 437f68a2adf57eb20e52e4e18770639e501c6bd88706cb9d34c3105eb5cac0c50833dbf52745a32d9ef5aaf230e18eea6c7c6a855fb69cce15f56d0548a0542d
7
- data.tar.gz: 6d9404d1f40a7084872a54ffe9e831196c0427cabcb03dab8b1c21dba8726b949ae4e2d5adf1e5e2715238ce83a4dbc88cea74466f06e07829a1c74efdba0220
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(csv_text, col_sep: sep)
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
@@ -1,3 +1,3 @@
1
1
  class CsvSeparatorDetector
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  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.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-04-26 00:00:00.000000000 Z
11
+ date: 2018-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler