slicing 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 014cfbd59f2b2e16e160d0188b59984f949eb0f6
4
- data.tar.gz: b42b46be39904cbf248cfea88bc1b8eee2e0ee1a
3
+ metadata.gz: 04356eda2f80b4f10b155cc6d8786ff1684f775d
4
+ data.tar.gz: e9a195109c4f8fb2bb6c4eddbba84c57b72a93c7
5
5
  SHA512:
6
- metadata.gz: 49dcfb2d5407fc30018d660bfaa07ea56c82a6d848a5b8de585450d4555ba16415c393cc9cfa01537801ec2a0eae3b48b024d38803799e14e2616579fdf985de
7
- data.tar.gz: a7717fc4df45630346a4c9e6003ae34f13617ec0d542631bc61e04c0a7d6caed253182d1ff61bb560b2ec4ddc2dfefd9c873aafb5d5ec28295fef7e84be5c9bb
6
+ metadata.gz: 065606b5a5f92a9f60dd80bd49f10c4a8fb3fbda13a3cdad48d68b87ce32f7fa9b87378583d4165f86c58e06ec63c3a0819721af509cf1001321fa1cef7e964f
7
+ data.tar.gz: f21fdb70ee8c0b2592053f251e35faf0b30181d57db2e52e6675457150f3a74e7287a4131e3b75d1ee2b95165ea52f216eb42b86d8f4dca315d3ee58a86a2e1b
@@ -9,6 +9,81 @@ module Slicing
9
9
  package_name 'slicing'
10
10
  default_task :help
11
11
 
12
+ # desc :gsub, ""
13
+ # def gsub path, output, first, second
14
+ # CSV.foreach(path,:headers=> true, :encoding => "ISO8859-1:utf-8") do |row|
15
+ # puts row
16
+ # row.map {|n| n.gsub(first,second) if n !=nil}
17
+ # CSV.open(output, "a+") do |csv|
18
+ # csv << row
19
+ # end
20
+ # end
21
+ #
22
+ # end
23
+ #
24
+ # desc :trim, "clean up by removing rows with column value"
25
+ # def trim path, output#, name, value
26
+ # CSV.foreach(path) do |row|
27
+ # row.map {|n| n.strip! || n}
28
+ # CSV.open(output, "a+") do |csv|
29
+ # csv << row
30
+ # end
31
+ # end
32
+ # end
33
+
34
+ desc :clean, "clean up by removing rows with column value"
35
+ def clean path, output, name, value
36
+ # puts "add header"
37
+ end
38
+
39
+ desc :add, "add a header"
40
+ def add path, output, *headers
41
+ index = 0
42
+ CSV.foreach(path) do |row|
43
+ CSV.open(output, "a+") do |csv|
44
+ if index == 0
45
+ csv << headers
46
+ end
47
+ csv << row
48
+ end
49
+ index = index +1
50
+ end
51
+ end
52
+
53
+ desc :show, "show a specific row"
54
+ def show path, output, start
55
+ index = 1
56
+ CSV.foreach(path) do |csv|
57
+ if index == start.to_i
58
+ puts csv
59
+ break
60
+ end
61
+ index = index + 1
62
+ end
63
+ end
64
+
65
+ desc :list, "list unique items in a column"
66
+ def list path, name
67
+ file_csv = CSV.read(path,:headers=> true, :encoding => "ISO8859-1:utf-8")
68
+ array = file_csv[name]
69
+ puts array.uniq
70
+ puts "--"
71
+ puts "#{array.uniq.count} items"
72
+ end
73
+
74
+ desc :reduce, "reduce csv to smaller rows"
75
+ def reduce path, output, start
76
+ index = 0
77
+ CSV.foreach(path) do |csv|
78
+ CSV.open(output, "a+") do |row|
79
+ if start.to_i > index #dangerous
80
+ csv << row
81
+ end
82
+ end
83
+ index = index +1
84
+ end
85
+ end
86
+
12
87
  desc :sample, "create a sample output"
13
88
  def sample path, output_path, size
14
89
  file_csv = CSV.read(path,:headers=> true, :encoding => "ISO8859-1:utf-8")
@@ -39,7 +114,6 @@ module Slicing
39
114
  end
40
115
  end
41
116
 
42
-
43
117
  desc :mask, "mask a particular column"
44
118
  def mask path, column_name, output_path
45
119
  original = CSV.read(path, { headers: true, return_headers: true, :encoding => "ISO8859-1:utf-8"})
@@ -50,6 +124,38 @@ module Slicing
50
124
  end
51
125
  end
52
126
 
127
+ desc :retain, "retain only these column"
128
+ def retain path, output, *names
129
+ value = ""
130
+ CSV.foreach(path) do |data|
131
+ value = data
132
+ break
133
+ end
134
+
135
+ array = []
136
+ names.each do |each_name|
137
+ if value.index(each_name) == nil
138
+ puts "#{each_name} is not a column name."
139
+ puts "--"
140
+ puts value
141
+ exit
142
+ end
143
+ array.push(value.index(each_name)) if value.index(each_name) != nil
144
+ end
145
+ # puts array.count
146
+ answer =
147
+ CSV.open(output,"a+") do |csv|
148
+ CSV.foreach(path) do |row|
149
+ answer = []
150
+ array.each do |each|
151
+ answer.push(row[each])
152
+ end
153
+ csv << answer
154
+ end
155
+ end
156
+
157
+ end
158
+
53
159
  desc :rm, "remove a column"
54
160
  method_option :utf, type: :string, aliases: '-u', default: "ISO8859-1:utf-8"
55
161
  method_option :headers, type: :boolean, aliases: '-h', default: true
@@ -90,6 +196,8 @@ module Slicing
90
196
  puts row
91
197
  puts "----"
92
198
  puts "#{row.count} columns"
199
+ puts "----"
200
+ print_header(row)
93
201
  exit
94
202
  end
95
203
  end
@@ -108,6 +216,8 @@ module Slicing
108
216
  puts "#{data.count} rows #{data[0].count} columns"
109
217
  puts "---"
110
218
  puts "#{data[0]}"
219
+ puts "---"
220
+ print_header(data[0])
111
221
  end
112
222
 
113
223
  desc :subset, "create a subset of the data"
@@ -150,6 +260,10 @@ module Slicing
150
260
 
151
261
  private
152
262
 
263
+ def print_header array
264
+ puts array.join(",") if array != nil
265
+ end
266
+
153
267
  def process_options headers, rowsep, utf
154
268
  if headers == nil
155
269
  headers = true
@@ -169,6 +283,10 @@ module Slicing
169
283
  hash
170
284
  end
171
285
 
286
+ def print_progress current, total
287
+ percent = current/total * 100
288
+ STDOUT.write "\r #{index} - #{percent}% completed."
289
+ end
172
290
 
173
291
  end
174
292
  end
@@ -1,3 +1,3 @@
1
1
  module Slicing
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
4
+ version: 0.1.1
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-07-08 00:00:00.000000000 Z
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,6 +58,7 @@ files:
58
58
  - bin/slicing
59
59
  - lib/slicing.rb
60
60
  - lib/slicing/version.rb
61
+ - slicing-0.1.0.gem
61
62
  - slicing.gemspec
62
63
  homepage: http://github.com/ytbryan/slicing
63
64
  licenses: