sycsvpro 0.0.2 → 0.0.3
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/html/Dsl.html +37 -0
- data/html/Sycsvpro/Calculator.html +16 -5
- data/html/Sycsvpro/Counter.html +35 -24
- data/html/Sycsvpro/Filter.html +4 -2
- data/html/Sycsvpro/Header.html +15 -4
- data/html/Sycsvpro/RowFilter.html +14 -2
- data/html/created.rid +11 -11
- data/html/js/search_index.js +1 -1
- data/html/table_of_contents.html +14 -9
- data/lib/sycsvpro/calculator.rb +4 -1
- data/lib/sycsvpro/counter.rb +11 -8
- data/lib/sycsvpro/dsl.rb +6 -0
- data/lib/sycsvpro/filter.rb +3 -1
- data/lib/sycsvpro/header.rb +4 -1
- data/lib/sycsvpro/row_filter.rb +4 -0
- data/lib/sycsvpro/version.rb +1 -1
- data/spec/sycsvpro/counter_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 667ff2c450da872ce5ad260befa8a88e6ae10a8a
|
4
|
+
data.tar.gz: acdff20054e66a346444891324926d9b30706162
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b6721313dbcaa99e8655ef74889fe812e711ec9321104e247830581d12532f68629818f4bf16452e07b4668058ee5286fc918203e7d565cf639bcd27afbb7f2
|
7
|
+
data.tar.gz: 69f3acda440ea098a05c4e905ee4dc8bfcd110f05d3093e93c4ba6244a1dc3d60f144c09b4ba1e065ed45a5e4901d362e6b02f29eb869060944c08ab7b124176
|
data/Gemfile.lock
CHANGED
data/html/Dsl.html
CHANGED
@@ -68,6 +68,8 @@
|
|
68
68
|
|
69
69
|
<li ><a href="#method-i-rows">#rows</a>
|
70
70
|
|
71
|
+
<li ><a href="#method-i-unstring">#unstring</a>
|
72
|
+
|
71
73
|
<li ><a href="#method-i-write_to">#write_to</a>
|
72
74
|
|
73
75
|
</ul>
|
@@ -149,6 +151,41 @@ provided by the caller</p>
|
|
149
151
|
|
150
152
|
|
151
153
|
|
154
|
+
</div>
|
155
|
+
|
156
|
+
|
157
|
+
<div id="method-i-unstring" class="method-detail ">
|
158
|
+
|
159
|
+
<div class="method-heading">
|
160
|
+
<span class="method-name">unstring</span><span
|
161
|
+
class="method-args">(line)</span>
|
162
|
+
|
163
|
+
<span class="method-click-advice">click to toggle source</span>
|
164
|
+
|
165
|
+
</div>
|
166
|
+
|
167
|
+
|
168
|
+
<div class="method-description">
|
169
|
+
|
170
|
+
<p>Remove leading and trailing “ and spaces as well as reducing more than 2
|
171
|
+
spaces between words from csv values like ”a“;ba g;c;”d“;e to a;b
|
172
|
+
ag;c;d;e</p>
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
<div class="method-source-code" id="unstring-source">
|
178
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/dsl.rb, line 32</span>
|
179
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">unstring</span>(<span class="ruby-identifier">line</span>)
|
180
|
+
<span class="ruby-identifier">line</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/(?<=^|;)\s*"?\s*|\s*"?\s*(?=;|$)/</span>, <span class="ruby-string">""</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/\s{2,}/</span>, <span class="ruby-string">" "</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">nil?</span>
|
181
|
+
<span class="ruby-keyword">end</span></pre>
|
182
|
+
</div>
|
183
|
+
|
184
|
+
</div>
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
152
189
|
</div>
|
153
190
|
|
154
191
|
|
@@ -65,7 +65,18 @@
|
|
65
65
|
|
66
66
|
</div>
|
67
67
|
|
68
|
-
|
68
|
+
<div id="includes-section" class="nav-section">
|
69
|
+
<h3>Included Modules</h3>
|
70
|
+
|
71
|
+
<ul class="link-list">
|
72
|
+
|
73
|
+
|
74
|
+
<li><a class="include" href="../Dsl.html">Dsl</a>
|
75
|
+
|
76
|
+
|
77
|
+
</ul>
|
78
|
+
</div>
|
79
|
+
|
69
80
|
|
70
81
|
<!-- Method Quickref -->
|
71
82
|
<div id="method-list-section" class="nav-section">
|
@@ -226,7 +237,7 @@ generated due to a arithmetic operation that creates new columns</p>
|
|
226
237
|
|
227
238
|
|
228
239
|
<div class="method-source-code" id="new-source">
|
229
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/calculator.rb, line
|
240
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/calculator.rb, line 31</span>
|
230
241
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>={})
|
231
242
|
<span class="ruby-ivar">@infile</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:infile</span>]
|
232
243
|
<span class="ruby-ivar">@outfile</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:outfile</span>]
|
@@ -272,7 +283,7 @@ generated due to a arithmetic operation that creates new columns</p>
|
|
272
283
|
|
273
284
|
|
274
285
|
<div class="method-source-code" id="execute-source">
|
275
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/calculator.rb, line
|
286
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/calculator.rb, line 46</span>
|
276
287
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">execute</span>
|
277
288
|
<span class="ruby-identifier">processed_header</span> = <span class="ruby-keyword">false</span>
|
278
289
|
|
@@ -289,7 +300,7 @@ generated due to a arithmetic operation that creates new columns</p>
|
|
289
300
|
|
290
301
|
<span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">row_filter</span>.<span class="ruby-identifier">process</span>(<span class="ruby-identifier">line</span>, <span class="ruby-identifier">row</span><span class="ruby-operator">:</span> <span class="ruby-identifier">index</span>).<span class="ruby-identifier">nil?</span>
|
291
302
|
|
292
|
-
<span class="ruby-ivar">@columns</span> = <span class="ruby-identifier">line</span
|
303
|
+
<span class="ruby-ivar">@columns</span> = <span class="ruby-identifier">unstring</span>(<span class="ruby-identifier">line</span>).<span class="ruby-identifier">chomp</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">';'</span>)
|
293
304
|
<span class="ruby-identifier">formulae</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col</span>, <span class="ruby-identifier">formula</span><span class="ruby-operator">|</span>
|
294
305
|
<span class="ruby-ivar">@columns</span>[<span class="ruby-identifier">col</span>.<span class="ruby-identifier">to_i</span>] = <span class="ruby-identifier">eval</span>(<span class="ruby-identifier">formula</span>)
|
295
306
|
<span class="ruby-keyword">end</span>
|
@@ -326,7 +337,7 @@ generated due to a arithmetic operation that creates new columns</p>
|
|
326
337
|
|
327
338
|
|
328
339
|
<div class="method-source-code" id="method_missing-source">
|
329
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/calculator.rb, line
|
340
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/calculator.rb, line 41</span>
|
330
341
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">id</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
331
342
|
<span class="ruby-identifier">to_number</span>(<span class="ruby-identifier">columns</span>[<span class="ruby-node">$1</span>.<span class="ruby-identifier">to_i</span>]) <span class="ruby-keyword">if</span> <span class="ruby-identifier">id</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/c(\d+)/</span>
|
332
343
|
<span class="ruby-keyword">end</span></pre>
|
data/html/Sycsvpro/Counter.html
CHANGED
@@ -65,7 +65,18 @@
|
|
65
65
|
|
66
66
|
</div>
|
67
67
|
|
68
|
-
|
68
|
+
<div id="includes-section" class="nav-section">
|
69
|
+
<h3>Included Modules</h3>
|
70
|
+
|
71
|
+
<ul class="link-list">
|
72
|
+
|
73
|
+
|
74
|
+
<li><a class="include" href="../Dsl.html">Dsl</a>
|
75
|
+
|
76
|
+
|
77
|
+
</ul>
|
78
|
+
</div>
|
79
|
+
|
69
80
|
|
70
81
|
<!-- Method Quickref -->
|
71
82
|
<div id="method-list-section" class="nav-section">
|
@@ -129,54 +140,54 @@ names and uses the count as the column value</p>
|
|
129
140
|
</div>
|
130
141
|
</div>
|
131
142
|
|
132
|
-
<div id="attribute-i-
|
143
|
+
<div id="attribute-i-heading" class="method-detail">
|
133
144
|
<div class="method-heading attribute-method-heading">
|
134
|
-
<span class="method-name">
|
145
|
+
<span class="method-name">heading</span><span
|
135
146
|
class="attribute-access-type">[R]</span>
|
136
147
|
</div>
|
137
148
|
|
138
149
|
<div class="method-description">
|
139
150
|
|
140
|
-
<p>
|
151
|
+
<p>header of the out file</p>
|
141
152
|
|
142
153
|
</div>
|
143
154
|
</div>
|
144
155
|
|
145
|
-
<div id="attribute-i-
|
156
|
+
<div id="attribute-i-infile" class="method-detail">
|
146
157
|
<div class="method-heading attribute-method-heading">
|
147
|
-
<span class="method-name">
|
158
|
+
<span class="method-name">infile</span><span
|
148
159
|
class="attribute-access-type">[R]</span>
|
149
160
|
</div>
|
150
161
|
|
151
162
|
<div class="method-description">
|
152
163
|
|
153
|
-
<p>
|
164
|
+
<p>infile contains the data that is operated on</p>
|
154
165
|
|
155
166
|
</div>
|
156
167
|
</div>
|
157
168
|
|
158
|
-
<div id="attribute-i-
|
169
|
+
<div id="attribute-i-key_column" class="method-detail">
|
159
170
|
<div class="method-heading attribute-method-heading">
|
160
|
-
<span class="method-name">
|
171
|
+
<span class="method-name">key_column</span><span
|
161
172
|
class="attribute-access-type">[R]</span>
|
162
173
|
</div>
|
163
174
|
|
164
175
|
<div class="method-description">
|
165
176
|
|
166
|
-
<p>
|
177
|
+
<p>values are assigned to the key column</p>
|
167
178
|
|
168
179
|
</div>
|
169
180
|
</div>
|
170
181
|
|
171
|
-
<div id="attribute-i-
|
182
|
+
<div id="attribute-i-key_values" class="method-detail">
|
172
183
|
<div class="method-heading attribute-method-heading">
|
173
|
-
<span class="method-name">
|
184
|
+
<span class="method-name">key_values</span><span
|
174
185
|
class="attribute-access-type">[R]</span>
|
175
186
|
</div>
|
176
187
|
|
177
188
|
<div class="method-description">
|
178
189
|
|
179
|
-
<p>values are assigned to the key column</p>
|
190
|
+
<p>values that are assigned to the key column</p>
|
180
191
|
|
181
192
|
</div>
|
182
193
|
</div>
|
@@ -236,14 +247,14 @@ names and uses the count as the column value</p>
|
|
236
247
|
|
237
248
|
|
238
249
|
<div class="method-source-code" id="new-source">
|
239
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line
|
250
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line 30</span>
|
240
251
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>={})
|
241
252
|
<span class="ruby-ivar">@infile</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:infile</span>]
|
242
253
|
<span class="ruby-ivar">@outfile</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:outfile</span>]
|
243
254
|
<span class="ruby-ivar">@key_column</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:key</span>].<span class="ruby-identifier">to_i</span>
|
244
255
|
<span class="ruby-ivar">@row_filter</span> = <span class="ruby-constant">RowFilter</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:rows</span>])
|
245
256
|
<span class="ruby-ivar">@col_filter</span> = <span class="ruby-constant">ColumnFilter</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:cols</span>], <span class="ruby-identifier">df</span><span class="ruby-operator">:</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:df</span>])
|
246
|
-
<span class="ruby-ivar">@
|
257
|
+
<span class="ruby-ivar">@key_values</span> = {}
|
247
258
|
<span class="ruby-ivar">@heading</span> = []
|
248
259
|
<span class="ruby-keyword">end</span></pre>
|
249
260
|
</div>
|
@@ -283,7 +294,7 @@ names and uses the count as the column value</p>
|
|
283
294
|
|
284
295
|
|
285
296
|
<div class="method-source-code" id="execute-source">
|
286
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line
|
297
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line 41</span>
|
287
298
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">execute</span>
|
288
299
|
<span class="ruby-identifier">process_file</span>
|
289
300
|
<span class="ruby-identifier">write_result</span>
|
@@ -317,16 +328,16 @@ names and uses the count as the column value</p>
|
|
317
328
|
|
318
329
|
|
319
330
|
<div class="method-source-code" id="process_file-source">
|
320
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line
|
331
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line 47</span>
|
321
332
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">process_file</span>
|
322
333
|
<span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">infile</span>).<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
|
323
334
|
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">col_filter</span>.<span class="ruby-identifier">process</span>(<span class="ruby-identifier">row_filter</span>.<span class="ruby-identifier">process</span>(<span class="ruby-identifier">line</span>.<span class="ruby-identifier">chomp</span>, <span class="ruby-identifier">row</span><span class="ruby-operator">:</span> <span class="ruby-identifier">index</span>))
|
324
335
|
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">empty?</span>
|
325
|
-
<span class="ruby-identifier">key</span> = <span class="ruby-identifier">line</span
|
326
|
-
<span class="ruby-identifier">
|
336
|
+
<span class="ruby-identifier">key</span> = <span class="ruby-identifier">unstring</span>(<span class="ruby-identifier">line</span>).<span class="ruby-identifier">split</span>(<span class="ruby-string">';'</span>)[<span class="ruby-identifier">key_column</span>]
|
337
|
+
<span class="ruby-identifier">key_value</span> = <span class="ruby-identifier">key_values</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">key_values</span>[<span class="ruby-identifier">key</span>] = { <span class="ruby-identifier">name</span><span class="ruby-operator">:</span> <span class="ruby-identifier">key</span>, <span class="ruby-identifier">elements</span><span class="ruby-operator">:</span> <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>) }
|
327
338
|
<span class="ruby-identifier">result</span>.<span class="ruby-identifier">chomp</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">';'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">column</span><span class="ruby-operator">|</span>
|
328
339
|
<span class="ruby-identifier">heading</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">column</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">heading</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">column</span>).<span class="ruby-identifier">nil?</span>
|
329
|
-
<span class="ruby-identifier">
|
340
|
+
<span class="ruby-identifier">key_value</span>[<span class="ruby-value">:elements</span>][<span class="ruby-identifier">column</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
330
341
|
<span class="ruby-keyword">end</span>
|
331
342
|
<span class="ruby-keyword">end</span>
|
332
343
|
<span class="ruby-keyword">end</span>
|
@@ -360,14 +371,14 @@ names and uses the count as the column value</p>
|
|
360
371
|
|
361
372
|
|
362
373
|
<div class="method-source-code" id="write_result-source">
|
363
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line
|
374
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line 62</span>
|
364
375
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">write_result</span>
|
365
376
|
<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">outfile</span>, <span class="ruby-string">'w'</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">out</span><span class="ruby-operator">|</span>
|
366
|
-
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> ([<span class="ruby-string">"
|
367
|
-
<span class="ruby-identifier">
|
377
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> ([<span class="ruby-string">"key"</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">heading</span>.<span class="ruby-identifier">sort</span>).<span class="ruby-identifier">join</span>(<span class="ruby-string">';'</span>)
|
378
|
+
<span class="ruby-identifier">key_values</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
368
379
|
<span class="ruby-identifier">line</span> = [<span class="ruby-identifier">k</span>]
|
369
380
|
<span class="ruby-identifier">heading</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
|
370
|
-
<span class="ruby-identifier">line</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">v</span>[<span class="ruby-value">:
|
381
|
+
<span class="ruby-identifier">line</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">v</span>[<span class="ruby-value">:elements</span>][<span class="ruby-identifier">h</span>]
|
371
382
|
<span class="ruby-keyword">end</span>
|
372
383
|
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">';'</span>)
|
373
384
|
<span class="ruby-keyword">end</span>
|
data/html/Sycsvpro/Filter.html
CHANGED
@@ -245,7 +245,7 @@ otherwise false</p>
|
|
245
245
|
|
246
246
|
|
247
247
|
<div class="method-source-code" id="has_filter-3F-source">
|
248
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/filter.rb, line
|
248
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/filter.rb, line 59</span>
|
249
249
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">has_filter?</span>
|
250
250
|
<span class="ruby-keyword">return</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">filter</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">pattern</span>.<span class="ruby-identifier">empty?</span>)
|
251
251
|
<span class="ruby-keyword">end</span></pre>
|
@@ -325,9 +325,11 @@ otherwise false</p>
|
|
325
325
|
<pre><span class="ruby-comment"># File lib/sycsvpro/filter.rb, line 45</span>
|
326
326
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">pivot_each_column</span>(<span class="ruby-identifier">values</span>=[])
|
327
327
|
<span class="ruby-identifier">pivot</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">column</span>, <span class="ruby-identifier">parameters</span><span class="ruby-operator">|</span>
|
328
|
+
<span class="ruby-identifier">value</span> = <span class="ruby-identifier">values</span>[<span class="ruby-identifier">parameters</span>[<span class="ruby-value">:col</span>].<span class="ruby-identifier">to_i</span>]
|
329
|
+
<span class="ruby-identifier">value</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/^"|"$/</span>, <span class="ruby-string">""</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
|
328
330
|
<span class="ruby-identifier">match</span> = <span class="ruby-keyword">false</span>
|
329
331
|
<span class="ruby-keyword">begin</span>
|
330
|
-
<span class="ruby-identifier">match</span> = <span class="ruby-identifier">eval</span>(<span class="ruby-identifier">parameters</span>[<span class="ruby-value">:operation</span>].<span class="ruby-identifier">gsub</span>(<span class="ruby-string">'[value]'</span>, <span class="ruby-identifier">
|
332
|
+
<span class="ruby-identifier">match</span> = <span class="ruby-identifier">eval</span>(<span class="ruby-identifier">parameters</span>[<span class="ruby-value">:operation</span>].<span class="ruby-identifier">gsub</span>(<span class="ruby-string">'[value]'</span>, <span class="ruby-identifier">value</span>))
|
331
333
|
<span class="ruby-keyword">rescue</span>
|
332
334
|
<span class="ruby-keyword">end</span>
|
333
335
|
<span class="ruby-keyword">yield</span> <span class="ruby-identifier">column</span>, <span class="ruby-identifier">match</span>
|
data/html/Sycsvpro/Header.html
CHANGED
@@ -65,7 +65,18 @@
|
|
65
65
|
|
66
66
|
</div>
|
67
67
|
|
68
|
-
|
68
|
+
<div id="includes-section" class="nav-section">
|
69
|
+
<h3>Included Modules</h3>
|
70
|
+
|
71
|
+
<ul class="link-list">
|
72
|
+
|
73
|
+
|
74
|
+
<li><a class="include" href="../Dsl.html">Dsl</a>
|
75
|
+
|
76
|
+
|
77
|
+
</ul>
|
78
|
+
</div>
|
79
|
+
|
69
80
|
|
70
81
|
<!-- Method Quickref -->
|
71
82
|
<div id="method-list-section" class="nav-section">
|
@@ -153,7 +164,7 @@
|
|
153
164
|
|
154
165
|
|
155
166
|
<div class="method-source-code" id="new-source">
|
156
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/header.rb, line
|
167
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/header.rb, line 16</span>
|
157
168
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">header</span>)
|
158
169
|
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">header</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">header</span>.<span class="ruby-identifier">empty?</span>
|
159
170
|
<span class="ruby-ivar">@header_cols</span> = <span class="ruby-identifier">header</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">','</span>)
|
@@ -198,10 +209,10 @@
|
|
198
209
|
|
199
210
|
|
200
211
|
<div class="method-source-code" id="process-source">
|
201
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/header.rb, line
|
212
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/header.rb, line 25</span>
|
202
213
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">process</span>(<span class="ruby-identifier">line</span>)
|
203
214
|
<span class="ruby-keyword">return</span> <span class="ruby-string">""</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@header_cols</span>.<span class="ruby-identifier">empty?</span>
|
204
|
-
<span class="ruby-ivar">@header_cols</span>[<span class="ruby-value">0</span>] = <span class="ruby-identifier">line</span
|
215
|
+
<span class="ruby-ivar">@header_cols</span>[<span class="ruby-value">0</span>] = <span class="ruby-identifier">unstring</span>(<span class="ruby-identifier">line</span>).<span class="ruby-identifier">split</span>(<span class="ruby-string">';'</span>)
|
205
216
|
<span class="ruby-ivar">@header_cols</span>.<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">';'</span>)
|
206
217
|
<span class="ruby-keyword">end</span></pre>
|
207
218
|
</div>
|
@@ -65,7 +65,18 @@
|
|
65
65
|
|
66
66
|
</div>
|
67
67
|
|
68
|
-
|
68
|
+
<div id="includes-section" class="nav-section">
|
69
|
+
<h3>Included Modules</h3>
|
70
|
+
|
71
|
+
<ul class="link-list">
|
72
|
+
|
73
|
+
|
74
|
+
<li><a class="include" href="../Dsl.html">Dsl</a>
|
75
|
+
|
76
|
+
|
77
|
+
</ul>
|
78
|
+
</div>
|
79
|
+
|
69
80
|
|
70
81
|
<!-- Method Quickref -->
|
71
82
|
<div id="method-list-section" class="nav-section">
|
@@ -130,8 +141,9 @@
|
|
130
141
|
|
131
142
|
|
132
143
|
<div class="method-source-code" id="process-source">
|
133
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/row_filter.rb, line
|
144
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/row_filter.rb, line 13</span>
|
134
145
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">process</span>(<span class="ruby-identifier">object</span>, <span class="ruby-identifier">options</span>={})
|
146
|
+
<span class="ruby-identifier">object</span> = <span class="ruby-identifier">unstring</span>(<span class="ruby-identifier">object</span>)
|
135
147
|
<span class="ruby-keyword">return</span> <span class="ruby-identifier">object</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">has_filter?</span>
|
136
148
|
<span class="ruby-identifier">filtered</span> = <span class="ruby-operator">!</span><span class="ruby-identifier">filter</span>.<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">uniq</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:row</span>]).<span class="ruby-identifier">nil?</span>
|
137
149
|
<span class="ruby-identifier">pattern</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
|
data/html/created.rid
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
|
1
|
+
Tue, 18 Feb 2014 21:41:43 +0100
|
2
2
|
README.rdoc Sun, 16 Feb 2014 22:01:46 +0100
|
3
3
|
lib/sycsvpro.rb Sun, 16 Feb 2014 21:33:36 +0100
|
4
|
-
lib/sycsvpro/analyzer.rb
|
5
|
-
lib/sycsvpro/calculator.rb
|
4
|
+
lib/sycsvpro/analyzer.rb Tue, 18 Feb 2014 19:57:28 +0100
|
5
|
+
lib/sycsvpro/calculator.rb Tue, 18 Feb 2014 19:53:34 +0100
|
6
6
|
lib/sycsvpro/collector.rb Sun, 16 Feb 2014 20:59:27 +0100
|
7
7
|
lib/sycsvpro/column_filter.rb Sun, 16 Feb 2014 21:10:11 +0100
|
8
|
-
lib/sycsvpro/counter.rb
|
9
|
-
lib/sycsvpro/dsl.rb
|
10
|
-
lib/sycsvpro/extractor.rb
|
11
|
-
lib/sycsvpro/filter.rb
|
12
|
-
lib/sycsvpro/header.rb
|
13
|
-
lib/sycsvpro/mapper.rb
|
8
|
+
lib/sycsvpro/counter.rb Tue, 18 Feb 2014 21:22:37 +0100
|
9
|
+
lib/sycsvpro/dsl.rb Tue, 18 Feb 2014 21:34:51 +0100
|
10
|
+
lib/sycsvpro/extractor.rb Tue, 18 Feb 2014 19:42:16 +0100
|
11
|
+
lib/sycsvpro/filter.rb Tue, 18 Feb 2014 20:23:57 +0100
|
12
|
+
lib/sycsvpro/header.rb Tue, 18 Feb 2014 19:50:26 +0100
|
13
|
+
lib/sycsvpro/mapper.rb Tue, 18 Feb 2014 19:45:47 +0100
|
14
14
|
lib/sycsvpro/profiler.rb Sun, 16 Feb 2014 21:31:39 +0100
|
15
|
-
lib/sycsvpro/row_filter.rb
|
16
|
-
lib/sycsvpro/version.rb
|
15
|
+
lib/sycsvpro/row_filter.rb Tue, 18 Feb 2014 19:45:25 +0100
|
16
|
+
lib/sycsvpro/version.rb Tue, 18 Feb 2014 20:01:04 +0100
|
17
17
|
bin/sycsvpro Sun, 16 Feb 2014 18:17:16 +0100
|
data/html/js/search_index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var search_data = {"index":{"searchIndex":["dsl","object","sycsvpro","analyzer","calculator","collector","columnfilter","counter","extractor","filter","header","mapper","profiler","rowfilter","execute()","execute()","execute()","execute()","execute()","execute()","has_filter?()","method_missing()","method_missing()","new()","new()","new()","new()","new()","new()","new()","new()","new()","pivot_each_column()","process()","process()","process()","process()","process_file()","result()","rows()","write_result()","write_to()","readme"],"longSearchIndex":["dsl","object","sycsvpro","sycsvpro::analyzer","sycsvpro::calculator","sycsvpro::collector","sycsvpro::columnfilter","sycsvpro::counter","sycsvpro::extractor","sycsvpro::filter","sycsvpro::header","sycsvpro::mapper","sycsvpro::profiler","sycsvpro::rowfilter","sycsvpro::calculator#execute()","sycsvpro::collector#execute()","sycsvpro::counter#execute()","sycsvpro::extractor#execute()","sycsvpro::mapper#execute()","sycsvpro::profiler#execute()","sycsvpro::filter#has_filter?()","sycsvpro::calculator#method_missing()","sycsvpro::filter#method_missing()","sycsvpro::analyzer::new()","sycsvpro::calculator::new()","sycsvpro::collector::new()","sycsvpro::counter::new()","sycsvpro::extractor::new()","sycsvpro::filter::new()","sycsvpro::header::new()","sycsvpro::mapper::new()","sycsvpro::profiler::new()","sycsvpro::filter#pivot_each_column()","sycsvpro::columnfilter#process()","sycsvpro::filter#process()","sycsvpro::header#process()","sycsvpro::rowfilter#process()","sycsvpro::counter#process_file()","sycsvpro::analyzer#result()","dsl#rows()","sycsvpro::counter#write_result()","dsl#write_to()",""],"info":[["Dsl","","Dsl.html","","<p>Methods to be used in customer specific script files\n"],["Object","","Object.html","",""],["Sycsvpro","","Sycsvpro.html","","<p>Operating csv files\n<p>Operating csv files\n<p>Operating csv files\n"],["Sycsvpro::Analyzer","","Sycsvpro/Analyzer.html","","<p>Analyzes the file structure\n"],["Sycsvpro::Calculator","","Sycsvpro/Calculator.html","","<p>Processes arithmetic operations on columns of a csv file. A column value\nhas to be a number. Possible …\n"],["Sycsvpro::Collector","","Sycsvpro/Collector.html","","<p>Collects values from rows and groups them in categories\n"],["Sycsvpro::ColumnFilter","","Sycsvpro/ColumnFilter.html","","<p>Creates a new column filter\n"],["Sycsvpro::Counter","","Sycsvpro/Counter.html","","<p>Creates a new counter that counts values and uses the values as column\nnames and uses the count as the …\n"],["Sycsvpro::Extractor","","Sycsvpro/Extractor.html","","<p>Extracts rows and columns from a csv file\n"],["Sycsvpro::Filter","","Sycsvpro/Filter.html","","<p>Creates a new filter that can be extended by sub-classes. A sub-class needs\nto override the process method …\n"],["Sycsvpro::Header","","Sycsvpro/Header.html","","<p>Creates a header\n"],["Sycsvpro::Mapper","","Sycsvpro/Mapper.html","","<p>Map values to new values described in a mapping file\n"],["Sycsvpro::Profiler","","Sycsvpro/Profiler.html","","<p>A profiler takes a Ruby script and executes the provided method in the\nscript\n"],["Sycsvpro::RowFilter","","Sycsvpro/RowFilter.html","","<p>Filters rows based on provided patterns\n"],["execute","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-i-execute","()","<p>Executes the calculator\n"],["execute","Sycsvpro::Collector","Sycsvpro/Collector.html#method-i-execute","()","<p>Execute the collector\n"],["execute","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-execute","()","<p>Executes the counter\n"],["execute","Sycsvpro::Extractor","Sycsvpro/Extractor.html#method-i-execute","()","<p>Executes the extractor\n"],["execute","Sycsvpro::Mapper","Sycsvpro/Mapper.html#method-i-execute","()","<p>Executes the mapper\n"],["execute","Sycsvpro::Profiler","Sycsvpro/Profiler.html#method-i-execute","(method)","<p>Executes the provided method in the Ruby script\n"],["has_filter?","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-has_filter-3F","()","<p>Checks whether a filter has been set. Returns true if filter has been set\notherwise false\n"],["method_missing","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-i-method_missing","(id, *args, &block)","<p>Retrieves the values from a row as the result of a arithmetic operation\n"],["method_missing","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-method_missing","(id, *args, &block)","<p>Creates the filters based on the given patterns\n"],["new","Sycsvpro::Analyzer","Sycsvpro/Analyzer.html#method-c-new","(file)","<p>Creates a new analyzer\n"],["new","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-c-new","(options={})","<p>Creates a new Calculator. Options expects :infile, :outfile, :rows and\n:columns. Optionally a header …\n"],["new","Sycsvpro::Collector","Sycsvpro/Collector.html#method-c-new","(options={})","<p>Creates a new Collector\n"],["new","Sycsvpro::Counter","Sycsvpro/Counter.html#method-c-new","(options={})","<p>Creates a new counter\n"],["new","Sycsvpro::Extractor","Sycsvpro/Extractor.html#method-c-new","(options={})","<p>Creates a new extractor\n"],["new","Sycsvpro::Filter","Sycsvpro/Filter.html#method-c-new","(values, options={})","<p>Creates a new filter\n"],["new","Sycsvpro::Header","Sycsvpro/Header.html#method-c-new","(header)","<p>Create a new header\n"],["new","Sycsvpro::Mapper","Sycsvpro/Mapper.html#method-c-new","(options={})","<p>Creates new mapper\n"],["new","Sycsvpro::Profiler","Sycsvpro/Profiler.html#method-c-new","(pro_file)","<p>Creates a new profiler\n"],["pivot_each_column","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-pivot_each_column","(values=[])","<p>Yields the column value and whether the filter matches the column\n"],["process","Sycsvpro::ColumnFilter","Sycsvpro/ColumnFilter.html#method-i-process","(object, options={})","<p>Processes the filter and returns the values that respect the filter\n"],["process","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-process","(object, options={})","<p>Processes the filter. Needs to be overridden by the sub-class\n"],["process","Sycsvpro::Header","Sycsvpro/Header.html#method-i-process","(line)","<p>Returns the header\n"],["process","Sycsvpro::RowFilter","Sycsvpro/RowFilter.html#method-i-process","(object, options={})","<p>Processes the filter on the given row\n"],["process_file","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-process_file","()","<p>Processes the counting on the in file\n"],["result","Sycsvpro::Analyzer","Sycsvpro/Analyzer.html#method-i-result","()","<p>Analyzes the file and returns the result\n"],["rows","Dsl","Dsl.html#method-i-rows","(options={})","<p>Retrieves rows and columns from the file and returns them to the block\nprovided by the caller\n"],["write_result","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-write_result","()","<p>Writes the results\n"],["write_to","Dsl","Dsl.html#method-i-write_to","(file)","<p>writes values provided by a block to the given file\n"],["README","","README_rdoc.html","","<p>sycsvpro\n<p>Author — Pierre Sugar (pierre@sugaryourcoffee.de)\n<p>Copyright — Copyright © 2014 by Pierre Sugar\n"]]}}
|
1
|
+
var search_data = {"index":{"searchIndex":["dsl","object","sycsvpro","analyzer","calculator","collector","columnfilter","counter","extractor","filter","header","mapper","profiler","rowfilter","execute()","execute()","execute()","execute()","execute()","execute()","has_filter?()","method_missing()","method_missing()","new()","new()","new()","new()","new()","new()","new()","new()","new()","pivot_each_column()","process()","process()","process()","process()","process_file()","result()","rows()","unstring()","write_result()","write_to()","readme"],"longSearchIndex":["dsl","object","sycsvpro","sycsvpro::analyzer","sycsvpro::calculator","sycsvpro::collector","sycsvpro::columnfilter","sycsvpro::counter","sycsvpro::extractor","sycsvpro::filter","sycsvpro::header","sycsvpro::mapper","sycsvpro::profiler","sycsvpro::rowfilter","sycsvpro::calculator#execute()","sycsvpro::collector#execute()","sycsvpro::counter#execute()","sycsvpro::extractor#execute()","sycsvpro::mapper#execute()","sycsvpro::profiler#execute()","sycsvpro::filter#has_filter?()","sycsvpro::calculator#method_missing()","sycsvpro::filter#method_missing()","sycsvpro::analyzer::new()","sycsvpro::calculator::new()","sycsvpro::collector::new()","sycsvpro::counter::new()","sycsvpro::extractor::new()","sycsvpro::filter::new()","sycsvpro::header::new()","sycsvpro::mapper::new()","sycsvpro::profiler::new()","sycsvpro::filter#pivot_each_column()","sycsvpro::columnfilter#process()","sycsvpro::filter#process()","sycsvpro::header#process()","sycsvpro::rowfilter#process()","sycsvpro::counter#process_file()","sycsvpro::analyzer#result()","dsl#rows()","dsl#unstring()","sycsvpro::counter#write_result()","dsl#write_to()",""],"info":[["Dsl","","Dsl.html","","<p>Methods to be used in customer specific script files\n"],["Object","","Object.html","",""],["Sycsvpro","","Sycsvpro.html","","<p>Operating csv files\n<p>Operating csv files\n<p>Operating csv files\n"],["Sycsvpro::Analyzer","","Sycsvpro/Analyzer.html","","<p>Analyzes the file structure\n"],["Sycsvpro::Calculator","","Sycsvpro/Calculator.html","","<p>Processes arithmetic operations on columns of a csv file. A column value\nhas to be a number. Possible …\n"],["Sycsvpro::Collector","","Sycsvpro/Collector.html","","<p>Collects values from rows and groups them in categories\n"],["Sycsvpro::ColumnFilter","","Sycsvpro/ColumnFilter.html","","<p>Creates a new column filter\n"],["Sycsvpro::Counter","","Sycsvpro/Counter.html","","<p>Creates a new counter that counts values and uses the values as column\nnames and uses the count as the …\n"],["Sycsvpro::Extractor","","Sycsvpro/Extractor.html","","<p>Extracts rows and columns from a csv file\n"],["Sycsvpro::Filter","","Sycsvpro/Filter.html","","<p>Creates a new filter that can be extended by sub-classes. A sub-class needs\nto override the process method …\n"],["Sycsvpro::Header","","Sycsvpro/Header.html","","<p>Creates a header\n"],["Sycsvpro::Mapper","","Sycsvpro/Mapper.html","","<p>Map values to new values described in a mapping file\n"],["Sycsvpro::Profiler","","Sycsvpro/Profiler.html","","<p>A profiler takes a Ruby script and executes the provided method in the\nscript\n"],["Sycsvpro::RowFilter","","Sycsvpro/RowFilter.html","","<p>Filters rows based on provided patterns\n"],["execute","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-i-execute","()","<p>Executes the calculator\n"],["execute","Sycsvpro::Collector","Sycsvpro/Collector.html#method-i-execute","()","<p>Execute the collector\n"],["execute","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-execute","()","<p>Executes the counter\n"],["execute","Sycsvpro::Extractor","Sycsvpro/Extractor.html#method-i-execute","()","<p>Executes the extractor\n"],["execute","Sycsvpro::Mapper","Sycsvpro/Mapper.html#method-i-execute","()","<p>Executes the mapper\n"],["execute","Sycsvpro::Profiler","Sycsvpro/Profiler.html#method-i-execute","(method)","<p>Executes the provided method in the Ruby script\n"],["has_filter?","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-has_filter-3F","()","<p>Checks whether a filter has been set. Returns true if filter has been set\notherwise false\n"],["method_missing","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-i-method_missing","(id, *args, &block)","<p>Retrieves the values from a row as the result of a arithmetic operation\n"],["method_missing","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-method_missing","(id, *args, &block)","<p>Creates the filters based on the given patterns\n"],["new","Sycsvpro::Analyzer","Sycsvpro/Analyzer.html#method-c-new","(file)","<p>Creates a new analyzer\n"],["new","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-c-new","(options={})","<p>Creates a new Calculator. Options expects :infile, :outfile, :rows and\n:columns. Optionally a header …\n"],["new","Sycsvpro::Collector","Sycsvpro/Collector.html#method-c-new","(options={})","<p>Creates a new Collector\n"],["new","Sycsvpro::Counter","Sycsvpro/Counter.html#method-c-new","(options={})","<p>Creates a new counter\n"],["new","Sycsvpro::Extractor","Sycsvpro/Extractor.html#method-c-new","(options={})","<p>Creates a new extractor\n"],["new","Sycsvpro::Filter","Sycsvpro/Filter.html#method-c-new","(values, options={})","<p>Creates a new filter\n"],["new","Sycsvpro::Header","Sycsvpro/Header.html#method-c-new","(header)","<p>Create a new header\n"],["new","Sycsvpro::Mapper","Sycsvpro/Mapper.html#method-c-new","(options={})","<p>Creates new mapper\n"],["new","Sycsvpro::Profiler","Sycsvpro/Profiler.html#method-c-new","(pro_file)","<p>Creates a new profiler\n"],["pivot_each_column","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-pivot_each_column","(values=[])","<p>Yields the column value and whether the filter matches the column\n"],["process","Sycsvpro::ColumnFilter","Sycsvpro/ColumnFilter.html#method-i-process","(object, options={})","<p>Processes the filter and returns the values that respect the filter\n"],["process","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-process","(object, options={})","<p>Processes the filter. Needs to be overridden by the sub-class\n"],["process","Sycsvpro::Header","Sycsvpro/Header.html#method-i-process","(line)","<p>Returns the header\n"],["process","Sycsvpro::RowFilter","Sycsvpro/RowFilter.html#method-i-process","(object, options={})","<p>Processes the filter on the given row\n"],["process_file","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-process_file","()","<p>Processes the counting on the in file\n"],["result","Sycsvpro::Analyzer","Sycsvpro/Analyzer.html#method-i-result","()","<p>Analyzes the file and returns the result\n"],["rows","Dsl","Dsl.html#method-i-rows","(options={})","<p>Retrieves rows and columns from the file and returns them to the block\nprovided by the caller\n"],["unstring","Dsl","Dsl.html#method-i-unstring","(line)","<p>Remove leading and trailing “ and spaces as well as reducing more than 2\nspaces between words from …\n"],["write_result","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-write_result","()","<p>Writes the results\n"],["write_to","Dsl","Dsl.html#method-i-write_to","(file)","<p>writes values provided by a block to the given file\n"],["README","","README_rdoc.html","","<p>sycsvpro\n<p>Author — Pierre Sugar (pierre@sugaryourcoffee.de)\n<p>Copyright — Copyright © 2014 by Pierre Sugar\n"]]}}
|
data/html/table_of_contents.html
CHANGED
@@ -151,9 +151,9 @@
|
|
151
151
|
<span class="container">Sycsvpro::Mapper</span>
|
152
152
|
|
153
153
|
<li class="method">
|
154
|
-
<a href="Sycsvpro/
|
154
|
+
<a href="Sycsvpro/Collector.html#method-i-execute">#execute</a>
|
155
155
|
—
|
156
|
-
<span class="container">Sycsvpro::
|
156
|
+
<span class="container">Sycsvpro::Collector</span>
|
157
157
|
|
158
158
|
<li class="method">
|
159
159
|
<a href="Sycsvpro/Extractor.html#method-i-execute">#execute</a>
|
@@ -161,9 +161,9 @@
|
|
161
161
|
<span class="container">Sycsvpro::Extractor</span>
|
162
162
|
|
163
163
|
<li class="method">
|
164
|
-
<a href="Sycsvpro/
|
164
|
+
<a href="Sycsvpro/Calculator.html#method-i-execute">#execute</a>
|
165
165
|
—
|
166
|
-
<span class="container">Sycsvpro::
|
166
|
+
<span class="container">Sycsvpro::Calculator</span>
|
167
167
|
|
168
168
|
<li class="method">
|
169
169
|
<a href="Sycsvpro/Filter.html#method-i-has_filter-3F">#has_filter?</a>
|
@@ -185,11 +185,6 @@
|
|
185
185
|
—
|
186
186
|
<span class="container">Sycsvpro::Filter</span>
|
187
187
|
|
188
|
-
<li class="method">
|
189
|
-
<a href="Sycsvpro/Filter.html#method-i-process">#process</a>
|
190
|
-
—
|
191
|
-
<span class="container">Sycsvpro::Filter</span>
|
192
|
-
|
193
188
|
<li class="method">
|
194
189
|
<a href="Sycsvpro/Header.html#method-i-process">#process</a>
|
195
190
|
—
|
@@ -200,6 +195,11 @@
|
|
200
195
|
—
|
201
196
|
<span class="container">Sycsvpro::ColumnFilter</span>
|
202
197
|
|
198
|
+
<li class="method">
|
199
|
+
<a href="Sycsvpro/Filter.html#method-i-process">#process</a>
|
200
|
+
—
|
201
|
+
<span class="container">Sycsvpro::Filter</span>
|
202
|
+
|
203
203
|
<li class="method">
|
204
204
|
<a href="Sycsvpro/RowFilter.html#method-i-process">#process</a>
|
205
205
|
—
|
@@ -220,6 +220,11 @@
|
|
220
220
|
—
|
221
221
|
<span class="container">Dsl</span>
|
222
222
|
|
223
|
+
<li class="method">
|
224
|
+
<a href="Dsl.html#method-i-unstring">#unstring</a>
|
225
|
+
—
|
226
|
+
<span class="container">Dsl</span>
|
227
|
+
|
223
228
|
<li class="method">
|
224
229
|
<a href="Sycsvpro/Counter.html#method-i-write_result">#write_result</a>
|
225
230
|
—
|
data/lib/sycsvpro/calculator.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'row_filter'
|
2
2
|
require_relative 'header'
|
3
|
+
require_relative 'dsl'
|
3
4
|
|
4
5
|
# Operating csv files
|
5
6
|
module Sycsvpro
|
@@ -9,6 +10,8 @@ module Sycsvpro
|
|
9
10
|
# operator like c1*2 will multiply the value of column 1 with 2.
|
10
11
|
class Calculator
|
11
12
|
|
13
|
+
include Dsl
|
14
|
+
|
12
15
|
# infile contains the data that is operated on
|
13
16
|
attr_reader :infile
|
14
17
|
# outfile is the file where the result is written to
|
@@ -56,7 +59,7 @@ module Sycsvpro
|
|
56
59
|
|
57
60
|
next if row_filter.process(line, row: index).nil?
|
58
61
|
|
59
|
-
@columns = line.chomp.split(';')
|
62
|
+
@columns = unstring(line).chomp.split(';')
|
60
63
|
formulae.each do |col, formula|
|
61
64
|
@columns[col.to_i] = eval(formula)
|
62
65
|
end
|
data/lib/sycsvpro/counter.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'row_filter'
|
2
2
|
require_relative 'column_filter'
|
3
|
+
require_relative 'dsl'
|
3
4
|
|
4
5
|
# Operating csv files
|
5
6
|
module Sycsvpro
|
@@ -8,6 +9,8 @@ module Sycsvpro
|
|
8
9
|
# as the column value
|
9
10
|
class Counter
|
10
11
|
|
12
|
+
include Dsl
|
13
|
+
|
11
14
|
# infile contains the data that is operated on
|
12
15
|
attr_reader :infile
|
13
16
|
# outfile is the file where the result is written to
|
@@ -19,7 +22,7 @@ module Sycsvpro
|
|
19
22
|
# filter that is used for columns
|
20
23
|
attr_reader :col_filter
|
21
24
|
# values that are assigned to the key column
|
22
|
-
attr_reader :
|
25
|
+
attr_reader :key_values
|
23
26
|
# header of the out file
|
24
27
|
attr_reader :heading
|
25
28
|
|
@@ -30,7 +33,7 @@ module Sycsvpro
|
|
30
33
|
@key_column = options[:key].to_i
|
31
34
|
@row_filter = RowFilter.new(options[:rows])
|
32
35
|
@col_filter = ColumnFilter.new(options[:cols], df: options[:df])
|
33
|
-
@
|
36
|
+
@key_values = {}
|
34
37
|
@heading = []
|
35
38
|
end
|
36
39
|
|
@@ -45,11 +48,11 @@ module Sycsvpro
|
|
45
48
|
File.new(infile).each_with_index do |line, index|
|
46
49
|
result = col_filter.process(row_filter.process(line.chomp, row: index))
|
47
50
|
unless result.nil? or result.empty?
|
48
|
-
key = line.split(';')[key_column]
|
49
|
-
|
51
|
+
key = unstring(line).split(';')[key_column]
|
52
|
+
key_value = key_values[key] || key_values[key] = { name: key, elements: Hash.new(0) }
|
50
53
|
result.chomp.split(';').each do |column|
|
51
54
|
heading << column if heading.index(column).nil?
|
52
|
-
|
55
|
+
key_value[:elements][column] += 1
|
53
56
|
end
|
54
57
|
end
|
55
58
|
end
|
@@ -58,11 +61,11 @@ module Sycsvpro
|
|
58
61
|
# Writes the results
|
59
62
|
def write_result
|
60
63
|
File.open(outfile, 'w') do |out|
|
61
|
-
out.puts (["
|
62
|
-
|
64
|
+
out.puts (["key"] + heading.sort).join(';')
|
65
|
+
key_values.each do |k,v|
|
63
66
|
line = [k]
|
64
67
|
heading.sort.each do |h|
|
65
|
-
line << v[:
|
68
|
+
line << v[:elements][h]
|
66
69
|
end
|
67
70
|
out.puts line.join(';')
|
68
71
|
end
|
data/lib/sycsvpro/dsl.rb
CHANGED
@@ -27,6 +27,12 @@ module Dsl
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
# Remove leading and trailing " and spaces as well as reducing more than 2 spaces between words
|
31
|
+
# from csv values like "a";ba g;c;"d";e to a;b ag;c;d;e
|
32
|
+
def unstring(line)
|
33
|
+
line.gsub(/(?<=^|;)\s*"?\s*|\s*"?\s*(?=;|$)/, "").gsub(/\s{2,}/, " ") unless line.nil?
|
34
|
+
end
|
35
|
+
|
30
36
|
private
|
31
37
|
|
32
38
|
# Assigns values to keys that are used in rows and yielded to the block
|
data/lib/sycsvpro/filter.rb
CHANGED
@@ -44,9 +44,11 @@ module Sycsvpro
|
|
44
44
|
# Yields the column value and whether the filter matches the column
|
45
45
|
def pivot_each_column(values=[])
|
46
46
|
pivot.each do |column, parameters|
|
47
|
+
value = values[parameters[:col].to_i]
|
48
|
+
value = value.strip.gsub(/^"|"$/, "") unless value.nil?
|
47
49
|
match = false
|
48
50
|
begin
|
49
|
-
match = eval(parameters[:operation].gsub('[value]',
|
51
|
+
match = eval(parameters[:operation].gsub('[value]', value))
|
50
52
|
rescue
|
51
53
|
end
|
52
54
|
yield column, match
|
data/lib/sycsvpro/header.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'filter'
|
2
|
+
require_relative 'dsl'
|
2
3
|
|
3
4
|
# Operating csv files
|
4
5
|
module Sycsvpro
|
@@ -6,6 +7,8 @@ module Sycsvpro
|
|
6
7
|
# Creates a header
|
7
8
|
class Header < Filter
|
8
9
|
|
10
|
+
include Dsl
|
11
|
+
|
9
12
|
# Header columns
|
10
13
|
attr_reader :header_cols
|
11
14
|
|
@@ -21,7 +24,7 @@ module Sycsvpro
|
|
21
24
|
# Returns the header
|
22
25
|
def process(line)
|
23
26
|
return "" if @header_cols.empty?
|
24
|
-
@header_cols[0] = line.split(';')
|
27
|
+
@header_cols[0] = unstring(line).split(';')
|
25
28
|
@header_cols.flatten.join(';')
|
26
29
|
end
|
27
30
|
end
|
data/lib/sycsvpro/row_filter.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'filter'
|
2
|
+
require_relative 'dsl'
|
2
3
|
|
3
4
|
# Operating csv files
|
4
5
|
module Sycsvpro
|
@@ -6,8 +7,11 @@ module Sycsvpro
|
|
6
7
|
# Filters rows based on provided patterns
|
7
8
|
class RowFilter < Filter
|
8
9
|
|
10
|
+
include Dsl
|
11
|
+
|
9
12
|
# Processes the filter on the given row
|
10
13
|
def process(object, options={})
|
14
|
+
object = unstring(object)
|
11
15
|
return object unless has_filter?
|
12
16
|
filtered = !filter.flatten.uniq.index(options[:row]).nil?
|
13
17
|
pattern.each do |p|
|
data/lib/sycsvpro/version.rb
CHANGED
@@ -15,7 +15,7 @@ module Sycsvpro
|
|
15
15
|
|
16
16
|
counter.execute
|
17
17
|
|
18
|
-
result = [ "
|
18
|
+
result = [ "key;con123;con332;con333;dri111;dri222;dri321",
|
19
19
|
"Fink;1;0;1;0;1;1",
|
20
20
|
"Haas;0;1;0;1;0;0",
|
21
21
|
"Gent;1;0;0;1;0;0",
|
@@ -35,7 +35,7 @@ module Sycsvpro
|
|
35
35
|
|
36
36
|
counter.execute
|
37
37
|
|
38
|
-
result = [ "
|
38
|
+
result = [ "key;1.1.2013-31.12.2014;<1.1.2013;>31.12.2014",
|
39
39
|
"Fink;0;0;2",
|
40
40
|
"Haas;0;1;0",
|
41
41
|
"Gent;1;0;0",
|
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.3
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|