comma_splice 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/lib/comma_splice/helpers/variable_column_finder.rb +3 -3
- data/lib/comma_splice/line_corrector.rb +4 -13
- data/lib/comma_splice/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74958cacc824b9e475df20acee4cc75ac354738ab4ed475a7ddc5f3ce5c7c553
|
4
|
+
data.tar.gz: 3b7129b58e24be7e9549e2971b994fd159e0d21675118e3c413a38dc1823db9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 112fea4670275a7222bbf60d13c8f61cea9386a60eaaf2cf16fd514f5c0ffd69a4e2e0453658408977607608340ca1e94e7f53581565d10014501c18d61a6570
|
7
|
+
data.tar.gz: b62a9835b22555efd4aad03c467c1d24f298d50c34b399171f8fc5bcb0d8c1ddfff1be14268599fe5ce67b88c6b9201c6c3e250e72de34361ba252594a6146e1
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
### 0.1.1 (January 24, 2020)
|
4
|
+
- [BUGFIX] handle case where all columns are equal widths
|
5
|
+
- [BUGFIX] Improve error message
|
6
|
+
- [IMPROVEMENT] simplify slicing [\#1](https://github.com/jkeen/comma_splice/pull/1) ([AlexMooney](https://github.com/AlexMooney))
|
7
|
+
|
8
|
+
### 0.1.0 (August 5th, 2019)
|
9
|
+
- Initial Release
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Comma Splice
|
2
2
|
|
3
|
-
This gem tackles one very specific problem: when CSVs have commas in the values and the values haven't been quoted. This determines which commas separate fields and which commas are part of a value, and corrects the file.
|
3
|
+
This gem tackles [one very specific problem](https://medium.com/@jeffkeen/how-to-correct-32-000-incorrect-csv-files-in-fewer-than-32-000-steps-a5f1ba25d951): when CSVs have commas in the values and the values haven't been quoted. This determines which commas separate fields and which commas are part of a value, and corrects the file.
|
4
4
|
|
5
5
|
For example, given the following CSV
|
6
6
|
|
@@ -19,7 +19,7 @@ which parses incorrectly as:
|
|
19
19
|
| 01-27-2019 @ 12:31:00 | Lester Sterling | Lester Sterling Special | Merritone Rock Steady 2: This Music Got Soul 1966-1967 | Dub Store |
|
20
20
|
|
21
21
|
|
22
|
-
Running this through `comma_splice
|
22
|
+
Running this through `comma_splice correct /path/to/file` will return this corrected content:
|
23
23
|
|
24
24
|
```
|
25
25
|
timestamp,artist,title,albumtitle,label
|
@@ -34,10 +34,10 @@ module CommaSplice
|
|
34
34
|
end
|
35
35
|
|
36
36
|
start_column = variables.find_index(true)
|
37
|
-
end_column = variables.reverse.find_index(true)
|
37
|
+
end_column = variables.reverse.find_index(true)
|
38
38
|
|
39
|
-
@start_column = start_column
|
40
|
-
@end_column = end_column
|
39
|
+
@start_column = start_column || 0
|
40
|
+
@end_column = (end_column || 1) * -1
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
@@ -13,8 +13,8 @@ module CommaSplice
|
|
13
13
|
@left_bounds = left_bounds
|
14
14
|
@right_bounds = right_bounds
|
15
15
|
|
16
|
-
raise 'right bounds must be
|
17
|
-
raise 'left bounds must be
|
16
|
+
raise 'right bounds must be negative' unless right_bounds.negative?
|
17
|
+
raise 'left bounds must be not be negative' if left_bounds.negative?
|
18
18
|
end
|
19
19
|
|
20
20
|
def needs_correcting?
|
@@ -35,17 +35,8 @@ module CommaSplice
|
|
35
35
|
# the only values that could contain an extra comma are "artist,title,albumtitle,label"
|
36
36
|
# therefore our left_bounds = 4, right_bounds = -5
|
37
37
|
|
38
|
-
values_before =
|
39
|
-
|
40
|
-
else
|
41
|
-
[]
|
42
|
-
end
|
43
|
-
|
44
|
-
values_after = if right_bounds < -1
|
45
|
-
values[(right_bounds + 1)..-1]
|
46
|
-
else
|
47
|
-
[]
|
48
|
-
end
|
38
|
+
values_before = values[0...left_bounds]
|
39
|
+
values_after = values.slice(right_bounds + 1, -(right_bounds + 1))
|
49
40
|
[values_before, corrector.correction, values_after].flatten.join(',')
|
50
41
|
end
|
51
42
|
|
data/lib/comma_splice/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comma_splice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Keen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,6 +104,7 @@ extra_rdoc_files: []
|
|
104
104
|
files:
|
105
105
|
- ".gitignore"
|
106
106
|
- ".rspec"
|
107
|
+
- CHANGELOG.md
|
107
108
|
- Gemfile
|
108
109
|
- Gemfile.lock
|
109
110
|
- LICENSE.txt
|
@@ -142,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
- !ruby/object:Gem::Version
|
143
144
|
version: '0'
|
144
145
|
requirements: []
|
145
|
-
|
146
|
-
rubygems_version: 2.7.8
|
146
|
+
rubygems_version: 3.0.6
|
147
147
|
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: Fixes CSVs with unescaped commas
|