sycsvpro 0.1.4 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,8 +4,10 @@ module Sycsvpro
4
4
 
5
5
  describe Table do
6
6
  before do
7
- @in_file = File.join(File.dirname(__FILE__), "files/table.csv")
8
- @out_file = File.join(File.dirname(__FILE__), "files/out.csv")
7
+ @in_file = File.join(File.dirname(__FILE__), "files/table.csv")
8
+ @in_file_revenues = File.join(File.dirname(__FILE__),
9
+ "files/table_revenues.csv")
10
+ @out_file = File.join(File.dirname(__FILE__), "files/out.csv")
9
11
  end
10
12
 
11
13
  it "should create headings from String and column values" do
@@ -60,6 +62,155 @@ module Sycsvpro
60
62
  end
61
63
  end
62
64
 
65
+ it "should add a sum row" do
66
+ Sycsvpro::Table.new(infile: @in_file,
67
+ outfile: @out_file,
68
+ header: "Year,c6,c1,c2+c3",
69
+ key: "c0=~/\\.(\\d{4})/,c6",
70
+ cols: "Value:+n1,c2+c3:+n1",
71
+ sum: "top:Value,c2+c3").execute
72
+
73
+ result = [ "Year;Country;Value;A1;B2;B4",
74
+ ";;95.2;41.0;21.0;33.2",
75
+ "2013;AT;53.7;20.5;0;33.2",
76
+ "2014;DE;21.0;0;21.0;0",
77
+ "2014;AT;20.5;20.5;0;0" ]
78
+
79
+ File.open(@out_file).each_with_index do |line, index|
80
+ line.chomp.should eq result[index]
81
+ end
82
+ end
83
+
84
+ it "should add a sum row after the heading" do
85
+ Sycsvpro::Table.new(infile: @in_file,
86
+ outfile: @out_file,
87
+ header: "c4,c5,c0=~/\\.(\\d{4})/",
88
+ key: "c4,c5",
89
+ cols: "c0=~/\\.(\\d{4})/:+n1",
90
+ sum: "TOP:c0=~/\\.(\\d{4})/").execute
91
+
92
+ result = [ "Customer Name;Customer-ID;2013;2014",
93
+ ";;53.7;41.5",
94
+ "Hank;133;20.5;20.5",
95
+ "Hans;234;0;21.0",
96
+ "Jack;432;33.2;0" ]
97
+
98
+ rows = 0
99
+
100
+ File.open(@out_file).each_with_index do |line, index|
101
+ line.chomp.should eq result[index]
102
+ rows += 1
103
+ end
104
+
105
+ rows.should eq result.size
106
+ end
107
+
108
+ it "should add a sum row at the bottom" do
109
+ Sycsvpro::Table.new(infile: @in_file,
110
+ outfile: @out_file,
111
+ header: "c4,c5,c0=~/\\.(\\d{4})/",
112
+ key: "c4,c5",
113
+ cols: "c0=~/\\.(\\d{4})/:+n1",
114
+ sum: "EOF:c0=~/\\.(\\d{4})/").execute
115
+
116
+ result = [ "Customer Name;Customer-ID;2013;2014",
117
+ "Hank;133;20.5;20.5",
118
+ "Hans;234;0;21.0",
119
+ "Jack;432;33.2;0",
120
+ ";;53.7;41.5" ]
121
+
122
+ rows = 0
123
+
124
+ File.open(@out_file).each_with_index do |line, index|
125
+ line.chomp.should eq result[index]
126
+ rows += 1
127
+ end
128
+
129
+ rows.should eq result.size
130
+ end
131
+
132
+ it "should process cols with commas within expression" do
133
+
134
+ sp_order_type = %w{ ZE ZEI Z0 }
135
+ rp_order_type = %w{ ZRN ZRK }
136
+
137
+ Sycsvpro::Table.new(infile: @in_file_revenues,
138
+ outfile: @out_file,
139
+ header: "Year,SP,RP,Total",
140
+ key: "c0=~/\\.(\\d{4})/",
141
+ cols: "SP:+n2 if #{sp_order_type}.index(c1),"+
142
+ "RP:+n2 if #{rp_order_type}.index(c1),"+
143
+ "Total:+n2",
144
+ nf: "DE",
145
+ sum: "top:SP,RP,Total").execute
146
+
147
+ result = [ "Year;SP;RP;Total",
148
+ ";345.2;3925.73;4270.93",
149
+ "2012;300.7;3580.1;3880.8",
150
+ "2013;44.5;345.63;390.13" ]
151
+
152
+ rows = 0
153
+
154
+ File.open(@out_file).each_with_index do |line, index|
155
+ line.chomp.should eq result[index]
156
+ rows += 1
157
+ end
158
+
159
+ rows.should eq result.size
160
+ end
161
+
162
+ it "should ignore commas within header expressions" do
163
+ Sycsvpro::Table.new(
164
+ infile: @in_file_revenues,
165
+ outfile: @out_file,
166
+ header: "Year,BEGINc1=~/^([A-Z]{1,2})/END,Total",
167
+ key: "c0=~/\\.(\\d{4})/",
168
+ cols: "c1=~/^([A-Z]{1,2})/:+n2,Total:+n2",
169
+ nf: "DE",
170
+ sum: "top:BEGINc1=~/^([A-Z]{1,2})/END,Total").execute
171
+
172
+ result = [ "Year;ZE;ZR;Total",
173
+ ";345.2;3925.73;4270.93",
174
+ "2012;300.7;3580.1;3880.8",
175
+ "2013;44.5;345.63;390.13" ]
176
+
177
+ rows = 0
178
+
179
+ File.open(@out_file).each_with_index do |line, index|
180
+ line.chomp.should eq result[index]
181
+ rows += 1
182
+ end
183
+
184
+ rows.should eq result.size
185
+
186
+ end
187
+
188
+ it "should ignore commas within key expressions" do
189
+ Sycsvpro::Table.new(
190
+ infile: @in_file_revenues,
191
+ outfile: @out_file,
192
+ header: "Year,BEGINc1=~/^([A-Z]{1,2})/END,Total",
193
+ key: "BEGINc0=~/\\d+\\.\\d+\\.(\\d{2,3})/END",
194
+ cols: "c1=~/^([A-Z]{1,2})/:+n2,Total:+n2",
195
+ nf: "DE",
196
+ sum: "top:BEGINc1=~/^([A-Z]{1,2})/END,Total").execute
197
+
198
+ result = [ "Year;ZE;ZR;Total",
199
+ ";345.2;3925.73;4270.93",
200
+ "201;345.2;3925.73;4270.93" ]
201
+
202
+ rows = 0
203
+
204
+ File.open(@out_file).each_with_index do |line, index|
205
+ line.chomp.should eq result[index]
206
+ rows += 1
207
+ end
208
+
209
+ rows.should eq result.size
210
+
211
+ end
212
+
213
+
63
214
  end
64
215
 
65
216
  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.1.0
10
+ 0.1.7
11
11
 
12
12
  GLOBAL OPTIONS
13
13
  -f, --file=FILE - CSV file to operate on (default: none)
@@ -20,16 +20,21 @@ COMMANDS
20
20
  aggregate - Aggregates the occurences of row values. Optionally adds a sum row
21
21
  allocate - Allocate specified columns from the file to a key value
22
22
  analyze - Analyze the CSV file regarding columns, rows and content
23
- calc - Process math operations on columns. Optionally adds a sum row
23
+ calc - Process operations on columns. Optionally add a sum row for columns withnumber
24
+ values
24
25
  collect - Collect values of specified rows and columns from the file and group them in
25
26
  categories
26
27
  count - Counts the occurences of column values. Uses column values as headings with count as
27
28
  values. Columns with a condition will be added as new columns and the condition will
28
29
  be set as column name. Optionally adds a sum row
30
+ edit - Creates a script/insert file or opens a script/insert file for editing if it exists
29
31
  execute - Executes the code provided in a file
30
32
  extract - Extract specified rows and columns from the file
31
33
  help - Shows a list of commands or help for one command
32
34
  insert - Inserts rows from a file to a csv-file
33
- list - List scripts in the scripts directory with optionally listing methods
35
+ join - Join two files based on a joint column value
36
+ list - Lists script or insert files in the scripts directory with optionally listing
37
+ methods of script files
34
38
  map - Map values in columns to new values
35
- sort - Sort columns based on column values
39
+ sort - Sort rows based on column values
40
+ table - Creates a table from a source file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sycsvpro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-23 00:00:00.000000000 Z
12
+ date: 2014-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -142,6 +142,7 @@ files:
142
142
  - lib/sycsvpro/filter.rb
143
143
  - lib/sycsvpro/header.rb
144
144
  - lib/sycsvpro/inserter.rb
145
+ - lib/sycsvpro/join.rb
145
146
  - lib/sycsvpro/mapper.rb
146
147
  - lib/sycsvpro/profiler.rb
147
148
  - lib/sycsvpro/row_filter.rb
@@ -164,6 +165,7 @@ files:
164
165
  - spec/sycsvpro/files/unsert.ins
165
166
  - spec/sycsvpro/header_spec.rb
166
167
  - spec/sycsvpro/inserter_spec.rb
168
+ - spec/sycsvpro/join_spec.rb
167
169
  - spec/sycsvpro/mapper_spec.rb
168
170
  - spec/sycsvpro/profiler_spec.rb
169
171
  - spec/sycsvpro/row_filter_spec.rb