cli_csv 0.0.0 → 0.0.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/cli_csv/splitter.rb +32 -0
- data/lib/cli_csv.rb +55 -3
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3033b944083e191af6e7637f9792056f2a4da39
|
4
|
+
data.tar.gz: 3570f196b9380713a668b2bf4080eb822051ec8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c8c95d1f3ad7c0168d520afbf29722cdb6eb566231ced44b83a7d0d27f68a7b84b4f4d17f9e00c64b5817da6d3d4dd3ef90dc90aa60d7ad49ffcfb90bca4c57
|
7
|
+
data.tar.gz: 5e359d423981a0dcd2a59b2f9fb1c34335667fae65c2e60618854e5cf935974199d169b1d63d625ec326846aaac629d3280c53aeead2697f2cece4cb0cbf613e
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Lumberjack
|
2
|
+
class Splitter
|
3
|
+
|
4
|
+
def self.split(path, division)
|
5
|
+
written = Array.new
|
6
|
+
headers = Array.new
|
7
|
+
headers_set = false
|
8
|
+
filename = path.split('/')[-1].split('.csv')[0]
|
9
|
+
puts filename
|
10
|
+
|
11
|
+
counter = 0
|
12
|
+
# splitting now
|
13
|
+
newcsv = CSV.open("#{filename}_#{counter}.csv", "wb")
|
14
|
+
CSV.foreach(File.path(path)) do |col|
|
15
|
+
counter += 1
|
16
|
+
if headers_set == false
|
17
|
+
headers.push(col)
|
18
|
+
headers_set = true
|
19
|
+
end
|
20
|
+
|
21
|
+
if (counter % division == 0)
|
22
|
+
newcsv.close
|
23
|
+
newcsv = CSV.open("#{filename}_#{counter / division}.csv", "wb")
|
24
|
+
headers.each { |i| newcsv << i }
|
25
|
+
end
|
26
|
+
|
27
|
+
newcsv << col.each { |i| [i.to_s] }
|
28
|
+
end
|
29
|
+
newcsv.close
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/cli_csv.rb
CHANGED
@@ -1,5 +1,57 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'cli_csv/splitter'
|
2
|
+
require 'csv'
|
3
|
+
include Lumberjack
|
4
|
+
|
5
|
+
class Cleaner
|
6
|
+
def self.start
|
7
|
+
puts "What do you want to do?"
|
8
|
+
puts "1. Split a single CSV into smaller ones"
|
9
|
+
puts "2. Split a bunch of CSVs into smaller ones"
|
10
|
+
puts "3. Remove duplicate rows from a CSV"
|
11
|
+
puts "4. Remove empty rows from a CSV"
|
12
|
+
puts "5. Delete CSV files from a directory that have few (or no) rows"
|
13
|
+
puts "6. Detect rows in a CSV that have a cell with too much text"
|
14
|
+
puts "7. Find a substring in a cell of a CSV"
|
15
|
+
decision = 0
|
16
|
+
until decision >= 1 && decision <= 7
|
17
|
+
print "Enter a number: "
|
18
|
+
decision = gets.chomp.to_i
|
19
|
+
end
|
20
|
+
case decision
|
21
|
+
when 1
|
22
|
+
self.split
|
23
|
+
when 2
|
24
|
+
puts "Coming soon!"
|
25
|
+
when 3
|
26
|
+
puts "Coming soon!"
|
27
|
+
when 4
|
28
|
+
puts "Coming soon!"
|
29
|
+
when 5
|
30
|
+
puts "Coming soon!"
|
31
|
+
when 6
|
32
|
+
puts "Coming soon!"
|
33
|
+
when 7
|
34
|
+
puts "Coming soon!"
|
35
|
+
end
|
4
36
|
end
|
37
|
+
|
38
|
+
def self.split
|
39
|
+
rows = 0
|
40
|
+
path = ''
|
41
|
+
until rows >= 1
|
42
|
+
print "How many rows do you want in your resulting files?: "
|
43
|
+
rows = gets.chomp.to_i
|
44
|
+
end
|
45
|
+
until File.file? path
|
46
|
+
print "What's the name of your master file?: "
|
47
|
+
path = gets.chomp
|
48
|
+
path.end_with?('.csv') ? path : path = "#{path}.csv"
|
49
|
+
unless File.file? path
|
50
|
+
puts "File not found.\nTry retyping the filename, using the full path or moving to its directory and try again."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
split = Splitter.split(path, rows)
|
54
|
+
self.start
|
55
|
+
end
|
56
|
+
|
5
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Schirmer
|
@@ -18,6 +18,7 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/cli_csv.rb
|
21
|
+
- lib/cli_csv/splitter.rb
|
21
22
|
homepage: http://rubygems.org/gems/cli_csv
|
22
23
|
licenses:
|
23
24
|
- GPL-3.0
|