sycsvpro 0.0.7 → 0.0.8
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/Gemfile.lock +1 -1
- data/README.md +38 -20
- data/README.rdoc +1 -0
- data/bin/sycsvpro +71 -11
- data/html/README_rdoc.html +8 -2
- data/html/Sycsvpro/ColumnTypeFilter.html +187 -0
- data/html/Sycsvpro/Filter.html +21 -5
- data/html/Sycsvpro/Inserter.html +275 -0
- data/html/Sycsvpro/ScriptCreator.html +16 -2
- data/html/Sycsvpro/ScriptList.html +7 -3
- data/html/Sycsvpro/Sorter.html +323 -0
- data/html/Sycsvpro.html +6 -0
- data/html/created.rid +12 -9
- data/html/index.html +14 -2
- data/html/js/search_index.js +1 -1
- data/html/table_of_contents.html +66 -32
- data/lib/sycsvpro/column_type_filter.rb +38 -0
- data/lib/sycsvpro/filter.rb +19 -0
- data/lib/sycsvpro/inserter.rb +40 -0
- data/lib/sycsvpro/script_creator.rb +10 -5
- data/lib/sycsvpro/script_list.rb +6 -2
- data/lib/sycsvpro/sorter.rb +62 -0
- data/lib/sycsvpro/version.rb +1 -1
- data/lib/sycsvpro.rb +2 -0
- data/spec/sycsvpro/allocator_spec.rb +2 -2
- data/spec/sycsvpro/files/insert.ins +1 -0
- data/spec/sycsvpro/files/unsert.ins +2 -0
- data/spec/sycsvpro/inserter_spec.rb +56 -0
- data/spec/sycsvpro/script_list_spec.rb +27 -0
- data/spec/sycsvpro/sorter_spec.rb +184 -0
- data/sycsvpro.rdoc +3 -1
- metadata +12 -2
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'sycsvpro/inserter'
|
2
|
+
|
3
|
+
module Sycsvpro
|
4
|
+
|
5
|
+
describe Inserter do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@in_file = File.join(File.dirname(__FILE__), "files/in.csv")
|
9
|
+
@out_file = File.join(File.dirname(__FILE__), "files/out.csv")
|
10
|
+
@insert_file = File.join(File.dirname(__FILE__), "files/insert.csv")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should insert rows to top of file" do
|
14
|
+
inserter = Inserter.new(infile: @in_file, outfile: @out_file, insert: @insert_file)
|
15
|
+
|
16
|
+
inserter.execute
|
17
|
+
|
18
|
+
result = [ ";H1;H2", "sum;=sum(b3:b4);=sum(c3:c4)", ";1;2", ";3;4",
|
19
|
+
"customer;contract-number;expires-on;machine;product1;product2",
|
20
|
+
"Fink;1234;20.12.2015;f1;con123;dri222",
|
21
|
+
"Haas;3322;1.10.2011;h1;con332;dri111",
|
22
|
+
"Gent;4323;1.3.2014;g1;con123;dri111",
|
23
|
+
"Fink;1234;30.12.2016;f2;con333;dri321",
|
24
|
+
"Rank;3232;\"1.5.2013\";r1;con332;dri321",
|
25
|
+
"Klig;4432;;k1;con332;dri222",
|
26
|
+
"fink;1234;;f3;con332;dri321" ]
|
27
|
+
|
28
|
+
File.open(@out_file).each_with_index do |line, index|
|
29
|
+
line.chomp.should eq result[index]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should insert rows to bottom of file" do
|
34
|
+
inserter = Inserter.new(infile: @in_file, outfile: @out_file, insert: @insert_file,
|
35
|
+
position: 'bottom')
|
36
|
+
|
37
|
+
inserter.execute
|
38
|
+
|
39
|
+
result = [ "customer;contract-number;expires-on;machine;product1;product2",
|
40
|
+
"Fink;1234;20.12.2015;f1;con123;dri222",
|
41
|
+
"Haas;3322;1.10.2011;h1;con332;dri111",
|
42
|
+
"Gent;4323;1.3.2014;g1;con123;dri111",
|
43
|
+
"Fink;1234;30.12.2016;f2;con333;dri321",
|
44
|
+
"Rank;3232;\"1.5.2013\";r1;con332;dri321",
|
45
|
+
"Klig;4432;;k1;con332;dri222",
|
46
|
+
"fink;1234;;f3;con332;dri321",
|
47
|
+
";H1;H2", "sum;=sum(b3:b4);=sum(c3:c4)", ";1;2", ";3;4" ]
|
48
|
+
|
49
|
+
File.open(@out_file).each_with_index do |line, index|
|
50
|
+
line.chomp.should eq result[index]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -8,6 +8,8 @@ module Sycsvpro
|
|
8
8
|
@dir = File.join(File.dirname(__FILE__), "files")
|
9
9
|
@file_1 = File.join(File.dirname(__FILE__), "files/profile.rb")
|
10
10
|
@file_2 = File.join(File.dirname(__FILE__), "files/script.rb")
|
11
|
+
@file_3 = File.join(File.dirname(__FILE__), "files/insert.ins")
|
12
|
+
@file_4 = File.join(File.dirname(__FILE__), "files/unsert.ins")
|
11
13
|
end
|
12
14
|
|
13
15
|
it "should list scripts" do
|
@@ -52,6 +54,31 @@ module Sycsvpro
|
|
52
54
|
script_list.execute.should eq result
|
53
55
|
end
|
54
56
|
|
57
|
+
it "should list all insert-files" do
|
58
|
+
script_list = ScriptList.new(dir: @dir, type: 'insert')
|
59
|
+
|
60
|
+
result = { @file_3 => [],
|
61
|
+
@file_4 => [] }
|
62
|
+
|
63
|
+
script_list.execute.should eq result
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should list specified insert-file" do
|
67
|
+
script_list = ScriptList.new(dir: @dir, script: 'unsert.ins', type: 'insert')
|
68
|
+
|
69
|
+
result = { @file_4 => [] }
|
70
|
+
|
71
|
+
script_list.execute.should eq result
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should list all insert-files with ignoring method switch" do
|
75
|
+
script_list = ScriptList.new(dir: @dir, type: 'insert', show_methods: true)
|
76
|
+
|
77
|
+
result = { @file_3 => [],
|
78
|
+
@file_4 => [] }
|
79
|
+
|
80
|
+
script_list.execute.should eq result
|
81
|
+
end
|
55
82
|
end
|
56
83
|
|
57
84
|
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'sycsvpro/sorter'
|
2
|
+
|
3
|
+
module Sycsvpro
|
4
|
+
|
5
|
+
describe Sorter do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@in_file = File.join(File.dirname(__FILE__), "files/in.csv")
|
9
|
+
@in_2_file = File.join(File.dirname(__FILE__), "files/in2.csv")
|
10
|
+
@out_file = File.join(File.dirname(__FILE__), "files/out.csv")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should sort by one column" do
|
14
|
+
rows = "1-7"
|
15
|
+
cols = "s:0"
|
16
|
+
df = "%d.%m.%Y"
|
17
|
+
|
18
|
+
sorter = Sorter.new(infile: @in_file, outfile: @out_file, rows: rows, cols: cols, df: df)
|
19
|
+
|
20
|
+
sorter.execute
|
21
|
+
|
22
|
+
result = [ "Fink;1234;20.12.2015;f1;con123;dri222",
|
23
|
+
"Fink;1234;30.12.2016;f2;con333;dri321",
|
24
|
+
"Gent;4323;1.3.2014;g1;con123;dri111",
|
25
|
+
"Haas;3322;1.10.2011;h1;con332;dri111",
|
26
|
+
"Klig;4432;;k1;con332;dri222",
|
27
|
+
"Rank;3232;1.5.2013;r1;con332;dri321",
|
28
|
+
"fink;1234;;f3;con332;dri321" ]
|
29
|
+
|
30
|
+
File.open(@out_file).each_with_index do |line, index|
|
31
|
+
line.chomp.should eq result[index]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should sort by two columns" do
|
36
|
+
rows = "1-7"
|
37
|
+
cols = "n:1,s:0"
|
38
|
+
df = "%d.%m.%Y"
|
39
|
+
|
40
|
+
sorter = Sorter.new(infile: @in_file, outfile: @out_file, rows: rows, cols: cols, df: df)
|
41
|
+
|
42
|
+
sorter.execute
|
43
|
+
|
44
|
+
result = [ "Fink;1234;20.12.2015;f1;con123;dri222",
|
45
|
+
"Fink;1234;30.12.2016;f2;con333;dri321",
|
46
|
+
"fink;1234;;f3;con332;dri321",
|
47
|
+
"Rank;3232;1.5.2013;r1;con332;dri321",
|
48
|
+
"Haas;3322;1.10.2011;h1;con332;dri111",
|
49
|
+
"Gent;4323;1.3.2014;g1;con123;dri111",
|
50
|
+
"Klig;4432;;k1;con332;dri222" ]
|
51
|
+
|
52
|
+
File.open(@out_file).each_with_index do |line, index|
|
53
|
+
line.chomp.should eq result[index]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should sort by column range" do
|
58
|
+
rows = "1-7"
|
59
|
+
cols = "s:3-5,s:0"
|
60
|
+
df = "%d.%m.%Y"
|
61
|
+
|
62
|
+
sorter = Sorter.new(infile: @in_file, outfile: @out_file, rows: rows, cols: cols, df: df)
|
63
|
+
|
64
|
+
sorter.execute
|
65
|
+
|
66
|
+
result = [ "Fink;1234;20.12.2015;f1;con123;dri222",
|
67
|
+
"Fink;1234;30.12.2016;f2;con333;dri321",
|
68
|
+
"fink;1234;;f3;con332;dri321",
|
69
|
+
"Gent;4323;1.3.2014;g1;con123;dri111",
|
70
|
+
"Haas;3322;1.10.2011;h1;con332;dri111",
|
71
|
+
"Klig;4432;;k1;con332;dri222",
|
72
|
+
"Rank;3232;1.5.2013;r1;con332;dri321" ]
|
73
|
+
|
74
|
+
File.open(@out_file).each_with_index do |line, index|
|
75
|
+
line.chomp.should eq result[index]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
it "should sort a date column" do
|
81
|
+
rows = "1-7"
|
82
|
+
cols = "d:2,s:0"
|
83
|
+
df = "%d.%m.%Y"
|
84
|
+
|
85
|
+
sorter = Sorter.new(infile: @in_file, outfile: @out_file, rows: rows, cols: cols, df: df)
|
86
|
+
|
87
|
+
sorter.execute
|
88
|
+
|
89
|
+
result = [ "Haas;3322;1.10.2011;h1;con332;dri111",
|
90
|
+
"Rank;3232;1.5.2013;r1;con332;dri321",
|
91
|
+
"Gent;4323;1.3.2014;g1;con123;dri111",
|
92
|
+
"Fink;1234;20.12.2015;f1;con123;dri222",
|
93
|
+
"Fink;1234;30.12.2016;f2;con333;dri321",
|
94
|
+
"Klig;4432;;k1;con332;dri222",
|
95
|
+
"fink;1234;;f3;con332;dri321" ]
|
96
|
+
|
97
|
+
File.open(@out_file).each_with_index do |line, index|
|
98
|
+
line.chomp.should eq result[index]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should sort descending" do
|
103
|
+
rows = "1-7"
|
104
|
+
cols = "d:2,s:0"
|
105
|
+
df = "%d.%m.%Y"
|
106
|
+
|
107
|
+
sorter = Sorter.new(infile: @in_file, outfile: @out_file, rows: rows, cols: cols, df: df,
|
108
|
+
desc: true)
|
109
|
+
|
110
|
+
sorter.execute
|
111
|
+
|
112
|
+
result = [ "fink;1234;;f3;con332;dri321",
|
113
|
+
"Klig;4432;;k1;con332;dri222",
|
114
|
+
"Fink;1234;30.12.2016;f2;con333;dri321",
|
115
|
+
"Fink;1234;20.12.2015;f1;con123;dri222",
|
116
|
+
"Gent;4323;1.3.2014;g1;con123;dri111",
|
117
|
+
"Rank;3232;1.5.2013;r1;con332;dri321",
|
118
|
+
"Haas;3322;1.10.2011;h1;con332;dri111" ]
|
119
|
+
|
120
|
+
File.open(@out_file).each_with_index do |line, index|
|
121
|
+
line.chomp.should eq result[index]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should sort empty numbers ascending" do
|
126
|
+
rows = "0-3"
|
127
|
+
cols = "n:1,s:0"
|
128
|
+
df = "%d.%m.%Y"
|
129
|
+
|
130
|
+
sorter = Sorter.new(infile: @in_2_file, outfile: @out_file, rows: rows, cols: cols, df: df,
|
131
|
+
desc: false)
|
132
|
+
|
133
|
+
sorter.execute
|
134
|
+
|
135
|
+
result = [ "bond;;1.1.2011;b3;con333;dri121",
|
136
|
+
"lins;;4.4.1999;l4;con999;dri444",
|
137
|
+
"arnd;1;3.1.2010;a2;;dri111" ]
|
138
|
+
|
139
|
+
File.open(@out_file).each_with_index do |line, index|
|
140
|
+
line.chomp.should eq result[index]
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should sort empty numbers descending" do
|
145
|
+
rows = "0-3"
|
146
|
+
cols = "n:1,s:0"
|
147
|
+
df = "%d.%m.%Y"
|
148
|
+
|
149
|
+
sorter = Sorter.new(infile: @in_2_file, outfile: @out_file, rows: rows, cols: cols, df: df,
|
150
|
+
desc: true)
|
151
|
+
|
152
|
+
sorter.execute
|
153
|
+
|
154
|
+
result = [ "bond;;1.1.2011;b3;con333;dri121",
|
155
|
+
"lins;;4.4.1999;l4;con999;dri444",
|
156
|
+
"arnd;1;3.1.2010;a2;;dri111" ].reverse
|
157
|
+
|
158
|
+
File.open(@out_file).each_with_index do |line, index|
|
159
|
+
line.chomp.should eq result[index]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should sort empty strings ascending" do
|
164
|
+
rows = "0-3"
|
165
|
+
cols = "s:4,s:0"
|
166
|
+
df = "%d.%m.%Y"
|
167
|
+
|
168
|
+
sorter = Sorter.new(infile: @in_2_file, outfile: @out_file, rows: rows, cols: cols, df: df,
|
169
|
+
desc: false)
|
170
|
+
|
171
|
+
sorter.execute
|
172
|
+
|
173
|
+
result = [ "arnd;1;3.1.2010;a2;;dri111",
|
174
|
+
"bond;;1.1.2011;b3;con333;dri121",
|
175
|
+
"lins;;4.4.1999;l4;con999;dri444" ]
|
176
|
+
|
177
|
+
File.open(@out_file).each_with_index do |line, index|
|
178
|
+
line.chomp.should eq result[index]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
data/sycsvpro.rdoc
CHANGED
@@ -7,7 +7,7 @@ SYNOPSIS
|
|
7
7
|
sycsvpro [global options] command [command options] [arguments...]
|
8
8
|
|
9
9
|
VERSION
|
10
|
-
0.0.
|
10
|
+
0.0.8
|
11
11
|
|
12
12
|
GLOBAL OPTIONS
|
13
13
|
-f, --file=FILE - CSV file to operate on (default: none)
|
@@ -27,5 +27,7 @@ COMMANDS
|
|
27
27
|
execute - Executes the code provided in a file
|
28
28
|
extract - Extract specified rows and columns from the file
|
29
29
|
help - Shows a list of commands or help for one command
|
30
|
+
insert - Inserts rows from a file to a csv-file
|
30
31
|
list - List scripts in the scripts directory with optionally listing methods
|
31
32
|
map - Map values in columns to new values
|
33
|
+
sort - Sort columns based on column values
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sycsvpro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre Sugar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -110,15 +110,18 @@ files:
|
|
110
110
|
- html/Sycsvpro/Calculator.html
|
111
111
|
- html/Sycsvpro/Collector.html
|
112
112
|
- html/Sycsvpro/ColumnFilter.html
|
113
|
+
- html/Sycsvpro/ColumnTypeFilter.html
|
113
114
|
- html/Sycsvpro/Counter.html
|
114
115
|
- html/Sycsvpro/Extractor.html
|
115
116
|
- html/Sycsvpro/Filter.html
|
116
117
|
- html/Sycsvpro/Header.html
|
118
|
+
- html/Sycsvpro/Inserter.html
|
117
119
|
- html/Sycsvpro/Mapper.html
|
118
120
|
- html/Sycsvpro/Profiler.html
|
119
121
|
- html/Sycsvpro/RowFilter.html
|
120
122
|
- html/Sycsvpro/ScriptCreator.html
|
121
123
|
- html/Sycsvpro/ScriptList.html
|
124
|
+
- html/Sycsvpro/Sorter.html
|
122
125
|
- html/created.rid
|
123
126
|
- html/fonts.css
|
124
127
|
- html/fonts/Lato-Light.ttf
|
@@ -167,16 +170,19 @@ files:
|
|
167
170
|
- lib/sycsvpro/calculator.rb
|
168
171
|
- lib/sycsvpro/collector.rb
|
169
172
|
- lib/sycsvpro/column_filter.rb
|
173
|
+
- lib/sycsvpro/column_type_filter.rb
|
170
174
|
- lib/sycsvpro/counter.rb
|
171
175
|
- lib/sycsvpro/dsl.rb
|
172
176
|
- lib/sycsvpro/extractor.rb
|
173
177
|
- lib/sycsvpro/filter.rb
|
174
178
|
- lib/sycsvpro/header.rb
|
179
|
+
- lib/sycsvpro/inserter.rb
|
175
180
|
- lib/sycsvpro/mapper.rb
|
176
181
|
- lib/sycsvpro/profiler.rb
|
177
182
|
- lib/sycsvpro/row_filter.rb
|
178
183
|
- lib/sycsvpro/script_creator.rb
|
179
184
|
- lib/sycsvpro/script_list.rb
|
185
|
+
- lib/sycsvpro/sorter.rb
|
180
186
|
- lib/sycsvpro/version.rb
|
181
187
|
- spec/sycsvpro/allocator_spec.rb
|
182
188
|
- spec/sycsvpro/analyze_spec.rb
|
@@ -184,12 +190,16 @@ files:
|
|
184
190
|
- spec/sycsvpro/collector_spec.rb
|
185
191
|
- spec/sycsvpro/counter_spec.rb
|
186
192
|
- spec/sycsvpro/extractor_spec.rb
|
193
|
+
- spec/sycsvpro/files/insert.ins
|
187
194
|
- spec/sycsvpro/files/mappings
|
188
195
|
- spec/sycsvpro/files/profile.rb
|
189
196
|
- spec/sycsvpro/files/script.rb
|
197
|
+
- spec/sycsvpro/files/unsert.ins
|
198
|
+
- spec/sycsvpro/inserter_spec.rb
|
190
199
|
- spec/sycsvpro/mapper_spec.rb
|
191
200
|
- spec/sycsvpro/profiler_spec.rb
|
192
201
|
- spec/sycsvpro/script_list_spec.rb
|
202
|
+
- spec/sycsvpro/sorter_spec.rb
|
193
203
|
- sycsvpro.gemspec
|
194
204
|
- sycsvpro.rdoc
|
195
205
|
homepage: https://github.com/sugaryourcoffee/syc-svpro
|