slicing 0.1.1 → 0.1.2.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -6
- data/lib/slicing.rb +102 -22
- data/lib/slicing/version.rb +1 -1
- data/slicing-0.1.1.gem +0 -0
- metadata +5 -5
- data/slicing-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99452dcf4332573735ceccb63a58171551d74865
|
4
|
+
data.tar.gz: 2cc0bf185269643d36bab763616dab8b382ee7cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 559539f466b76abd8f9cfa8acd6985afe6dbe8ea88ffc85c785217e4ed45ec9167198f038e2fdaf980dfd6eb3959717ffd17a900897ad67ebc29066470c2542e
|
7
|
+
data.tar.gz: d2cc88bacf8b1c5dde31957e78c2342bb7aabac8b3dc7ee1a69c115d86762d68bbf73e8d5761cc14d43a6cffa258700f5f5d8bf257e47067b9762645218a1f61
|
data/README.md
CHANGED
@@ -1,14 +1,25 @@
|
|
1
1
|
# Slicing
|
2
|
-
:v:
|
2
|
+
:v: Instant slice and dice your csv files for quick analysis via command line.
|
3
3
|
|
4
|
-
# Reason for making slicing
|
5
|
-
No database required, mom!
|
6
4
|
|
7
|
-
|
5
|
+
#Features
|
8
6
|
|
9
|
-
|
7
|
+
- `slicing keep` - produce a csv with specific columns kept.
|
8
|
+
|
9
|
+
eg. `slicing keep input.csv output.csv 'Column1' 'Column2' 'Column6'`
|
10
|
+
|
11
|
+
- `slicing count` - count the row csv and produce the column.
|
12
|
+
|
13
|
+
eg. `slicing count input.csv`
|
14
|
+
|
15
|
+
- `slicing head` - print the header only
|
16
|
+
|
17
|
+
eg. `slicing head input.csv`
|
18
|
+
|
19
|
+
- `slicing first` - return the first line of data of the csv file.
|
20
|
+
|
21
|
+
eg. `slicing first input.csv`
|
10
22
|
|
11
|
-
Hence, slicing is created to make it easy to slice csv files from terminal.
|
12
23
|
|
13
24
|
## Installation
|
14
25
|
|
data/lib/slicing.rb
CHANGED
@@ -9,6 +9,29 @@ module Slicing
|
|
9
9
|
package_name 'slicing'
|
10
10
|
default_task :help
|
11
11
|
|
12
|
+
|
13
|
+
desc :produce, "produce output.csv with the column value equal to given value"
|
14
|
+
def produce path, column_name, value, output
|
15
|
+
index = 0
|
16
|
+
str = ""
|
17
|
+
CSV.foreach(path, :headers => true, encoding: "ISO8859-1:utf-8") do |row|
|
18
|
+
str = row
|
19
|
+
break
|
20
|
+
end
|
21
|
+
index = str.index(column_name)
|
22
|
+
answer = 0
|
23
|
+
CSV.open(output, "a+") do |csv|
|
24
|
+
CSV.foreach(path) do |row|
|
25
|
+
csv << row if row[index] == value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc :clean, "clean up by removing rows with column value"
|
31
|
+
def clean path, output, name, value
|
32
|
+
# puts "add header"
|
33
|
+
end
|
34
|
+
|
12
35
|
# desc :gsub, ""
|
13
36
|
# def gsub path, output, first, second
|
14
37
|
# CSV.foreach(path,:headers=> true, :encoding => "ISO8859-1:utf-8") do |row|
|
@@ -31,11 +54,80 @@ module Slicing
|
|
31
54
|
# end
|
32
55
|
# end
|
33
56
|
|
34
|
-
desc :
|
35
|
-
def
|
36
|
-
|
57
|
+
desc :cat, "cat two csv files and keep the headers using the first csv"
|
58
|
+
def cat path, path_column, path2, path2_column, output
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
desc :combine, "combine"
|
63
|
+
def combine path, path_column, path2, path2_column, output
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
desc :append, "append"
|
68
|
+
def append path, output, value
|
69
|
+
data_to_merge = CSV.read(path,:headers=> true, :encoding => "ISO8859-1:utf-8") #TODO: is this a data
|
70
|
+
CSV.open(output, "a+") do |csv|
|
71
|
+
data_to_merge.each_with_index do |data,index|
|
72
|
+
csv << data.push(value)
|
73
|
+
end
|
74
|
+
end
|
37
75
|
end
|
38
76
|
|
77
|
+
desc :keep, "keep the columns"
|
78
|
+
def keep path, output, *column
|
79
|
+
data = CSV.read(path, :headers=> true, :encoding => "ISO8859-1:utf-8") #2014
|
80
|
+
header = data[0]
|
81
|
+
column_array = []
|
82
|
+
column.size.times do |index|
|
83
|
+
column_array.push(header.index(column[index]))
|
84
|
+
end
|
85
|
+
CSV.open(output,"a+") do |csv|
|
86
|
+
data.each_with_index do |row,index|
|
87
|
+
array = []
|
88
|
+
column.size.times do |value|
|
89
|
+
array.push(row[column[value]])
|
90
|
+
end
|
91
|
+
csv << array
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
desc :equal, "equal "
|
98
|
+
def equal path, column_name, value
|
99
|
+
index = 0
|
100
|
+
str = ""
|
101
|
+
CSV.foreach(path, :headers => true, encoding: "ISO8859-1:utf-8") do |row|
|
102
|
+
str = row
|
103
|
+
break
|
104
|
+
end
|
105
|
+
# array = str.to_s.split(",")
|
106
|
+
index = str.index(column_name)
|
107
|
+
#get the number
|
108
|
+
answer = 0
|
109
|
+
CSV.foreach(path) do |row|
|
110
|
+
answer = answer + 1 if row[index] == value
|
111
|
+
end
|
112
|
+
puts answer
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
desc :remove, "remove a header"
|
118
|
+
def remove path, output
|
119
|
+
index = 0
|
120
|
+
CSV.foreach(path) do |row|
|
121
|
+
CSV.open(output, "a+") do |csv|
|
122
|
+
if index != 0
|
123
|
+
csv << row
|
124
|
+
end
|
125
|
+
end
|
126
|
+
index = index +1
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
39
131
|
desc :add, "add a header"
|
40
132
|
def add path, output, *headers
|
41
133
|
index = 0
|
@@ -198,6 +290,8 @@ module Slicing
|
|
198
290
|
puts "#{row.count} columns"
|
199
291
|
puts "----"
|
200
292
|
print_header(row)
|
293
|
+
puts "----"
|
294
|
+
print_header_with_quote(row)
|
201
295
|
exit
|
202
296
|
end
|
203
297
|
end
|
@@ -218,6 +312,8 @@ module Slicing
|
|
218
312
|
puts "#{data[0]}"
|
219
313
|
puts "---"
|
220
314
|
print_header(data[0])
|
315
|
+
puts "---"
|
316
|
+
print_header_with_quote(data[0])
|
221
317
|
end
|
222
318
|
|
223
319
|
desc :subset, "create a subset of the data"
|
@@ -225,7 +321,6 @@ module Slicing
|
|
225
321
|
def subset(csv_file, output)
|
226
322
|
path = csv_file
|
227
323
|
output_directory = output #"/Users/ytbryan/Desktop/output/subset-2015.csv" #output directory
|
228
|
-
# options[:num] == nil ? (stop = 10) : (stop = options[:num])
|
229
324
|
stop = options[:line]
|
230
325
|
counter = 0
|
231
326
|
CSV.foreach(path, :headers => false, encoding: "ISO8859-1:utf-8") do |row|
|
@@ -240,30 +335,15 @@ module Slicing
|
|
240
335
|
end
|
241
336
|
end
|
242
337
|
|
243
|
-
# desc :subsetagain, ""
|
244
|
-
# def subsetagain csv_file, output, value=10
|
245
|
-
# path = csv_file
|
246
|
-
# output_directory = output #"/Users/ytbryan/Desktop/output/subset-2015.csv" #output directory
|
247
|
-
# stop = value
|
248
|
-
# counter = 0
|
249
|
-
# CSV.foreach(path, :headers => false, :row_sep => "\r\n", encoding: "ISO8859-1:utf-8") do |row|
|
250
|
-
# exit if counter == stop
|
251
|
-
# begin
|
252
|
-
# counter = counter + 1
|
253
|
-
# CSV.open(output_directory, "a+") do |csv|
|
254
|
-
# csv << row
|
255
|
-
# end
|
256
|
-
# rescue
|
257
|
-
# end
|
258
|
-
# end
|
259
|
-
# end
|
260
|
-
|
261
338
|
private
|
262
339
|
|
263
340
|
def print_header array
|
264
341
|
puts array.join(",") if array != nil
|
265
342
|
end
|
266
343
|
|
344
|
+
def print_header_with_quote array
|
345
|
+
puts "#{"array.join("' '")"}" if array != nil
|
346
|
+
end
|
267
347
|
def process_options headers, rowsep, utf
|
268
348
|
if headers == nil
|
269
349
|
headers = true
|
data/lib/slicing/version.rb
CHANGED
data/slicing-0.1.1.gem
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slicing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Lim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,7 +58,7 @@ files:
|
|
58
58
|
- bin/slicing
|
59
59
|
- lib/slicing.rb
|
60
60
|
- lib/slicing/version.rb
|
61
|
-
- slicing-0.1.
|
61
|
+
- slicing-0.1.1.gem
|
62
62
|
- slicing.gemspec
|
63
63
|
homepage: http://github.com/ytbryan/slicing
|
64
64
|
licenses:
|
@@ -75,9 +75,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - "
|
78
|
+
- - ">"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
80
|
+
version: 1.3.1
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project:
|
83
83
|
rubygems_version: 2.5.1
|
data/slicing-0.1.0.gem
DELETED
Binary file
|