sycsvpro 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- 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,275 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class Sycsvpro::Inserter - Your application title</title>
|
8
|
+
|
9
|
+
<link href="../fonts.css" rel="stylesheet">
|
10
|
+
<link href="../rdoc.css" rel="stylesheet">
|
11
|
+
|
12
|
+
<script type="text/javascript">
|
13
|
+
var rdoc_rel_prefix = "../";
|
14
|
+
</script>
|
15
|
+
|
16
|
+
<script src="../js/jquery.js"></script>
|
17
|
+
<script src="../js/navigation.js"></script>
|
18
|
+
<script src="../js/search_index.js"></script>
|
19
|
+
<script src="../js/search.js"></script>
|
20
|
+
<script src="../js/searcher.js"></script>
|
21
|
+
<script src="../js/darkfish.js"></script>
|
22
|
+
|
23
|
+
|
24
|
+
<body id="top" role="document" class="class">
|
25
|
+
<nav role="navigation">
|
26
|
+
<div id="project-navigation">
|
27
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
28
|
+
<h2>
|
29
|
+
<a href="../index.html" rel="home">Home</a>
|
30
|
+
</h2>
|
31
|
+
|
32
|
+
<div id="table-of-contents-navigation">
|
33
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
34
|
+
<a href="../table_of_contents.html#classes">Classes</a>
|
35
|
+
<a href="../table_of_contents.html#methods">Methods</a>
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
40
|
+
<form action="#" method="get" accept-charset="utf-8">
|
41
|
+
<div id="search-field-wrapper">
|
42
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
43
|
+
aria-autocomplete="list" aria-controls="search-results"
|
44
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
45
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<ul id="search-results" aria-label="Search Results"
|
49
|
+
aria-busy="false" aria-expanded="false"
|
50
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
51
|
+
</form>
|
52
|
+
</div>
|
53
|
+
|
54
|
+
</div>
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
<div id="class-metadata">
|
59
|
+
|
60
|
+
<div id="parent-class-section" class="nav-section">
|
61
|
+
<h3>Parent</h3>
|
62
|
+
|
63
|
+
|
64
|
+
<p class="link"><a href="../Object.html">Object</a>
|
65
|
+
|
66
|
+
</div>
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
<!-- Method Quickref -->
|
71
|
+
<div id="method-list-section" class="nav-section">
|
72
|
+
<h3>Methods</h3>
|
73
|
+
|
74
|
+
<ul class="link-list" role="directory">
|
75
|
+
|
76
|
+
<li ><a href="#method-c-new">::new</a>
|
77
|
+
|
78
|
+
<li ><a href="#method-i-execute">#execute</a>
|
79
|
+
|
80
|
+
</ul>
|
81
|
+
</div>
|
82
|
+
|
83
|
+
</div>
|
84
|
+
</nav>
|
85
|
+
|
86
|
+
<main role="main" aria-labelledby="class-Sycsvpro::Inserter">
|
87
|
+
<h1 id="class-Sycsvpro::Inserter" class="class">
|
88
|
+
class Sycsvpro::Inserter
|
89
|
+
</h1>
|
90
|
+
|
91
|
+
<section class="description">
|
92
|
+
|
93
|
+
<p>Insert a text file into another textfile at a specified position</p>
|
94
|
+
|
95
|
+
</section>
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
<section class="attribute-method-details" class="method-section">
|
109
|
+
<header>
|
110
|
+
<h3>Attributes</h3>
|
111
|
+
</header>
|
112
|
+
|
113
|
+
|
114
|
+
<div id="attribute-i-infile" class="method-detail">
|
115
|
+
<div class="method-heading attribute-method-heading">
|
116
|
+
<span class="method-name">infile</span><span
|
117
|
+
class="attribute-access-type">[R]</span>
|
118
|
+
</div>
|
119
|
+
|
120
|
+
<div class="method-description">
|
121
|
+
|
122
|
+
<p>file to insert lines to</p>
|
123
|
+
|
124
|
+
</div>
|
125
|
+
</div>
|
126
|
+
|
127
|
+
<div id="attribute-i-insert" class="method-detail">
|
128
|
+
<div class="method-heading attribute-method-heading">
|
129
|
+
<span class="method-name">insert</span><span
|
130
|
+
class="attribute-access-type">[R]</span>
|
131
|
+
</div>
|
132
|
+
|
133
|
+
<div class="method-description">
|
134
|
+
|
135
|
+
<p>file that contains the lines to insert</p>
|
136
|
+
|
137
|
+
</div>
|
138
|
+
</div>
|
139
|
+
|
140
|
+
<div id="attribute-i-outfile" class="method-detail">
|
141
|
+
<div class="method-heading attribute-method-heading">
|
142
|
+
<span class="method-name">outfile</span><span
|
143
|
+
class="attribute-access-type">[R]</span>
|
144
|
+
</div>
|
145
|
+
|
146
|
+
<div class="method-description">
|
147
|
+
|
148
|
+
<p>file to write result to</p>
|
149
|
+
|
150
|
+
</div>
|
151
|
+
</div>
|
152
|
+
|
153
|
+
<div id="attribute-i-position" class="method-detail">
|
154
|
+
<div class="method-heading attribute-method-heading">
|
155
|
+
<span class="method-name">position</span><span
|
156
|
+
class="attribute-access-type">[R]</span>
|
157
|
+
</div>
|
158
|
+
|
159
|
+
<div class="method-description">
|
160
|
+
|
161
|
+
<p>position (top or bottom) where to insert the rows</p>
|
162
|
+
|
163
|
+
</div>
|
164
|
+
</div>
|
165
|
+
|
166
|
+
</section>
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
|
171
|
+
<header>
|
172
|
+
<h3>Public Class Methods</h3>
|
173
|
+
</header>
|
174
|
+
|
175
|
+
|
176
|
+
<div id="method-c-new" class="method-detail ">
|
177
|
+
|
178
|
+
<div class="method-heading">
|
179
|
+
<span class="method-name">new</span><span
|
180
|
+
class="method-args">(options={})</span>
|
181
|
+
|
182
|
+
<span class="method-click-advice">click to toggle source</span>
|
183
|
+
|
184
|
+
</div>
|
185
|
+
|
186
|
+
|
187
|
+
<div class="method-description">
|
188
|
+
|
189
|
+
<p>Creates an <a href="Inserter.html">Inserter</a> and takes options infile,
|
190
|
+
outfile, insert-file and position where to insert the insert-file content.
|
191
|
+
Default position is top</p>
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
<div class="method-source-code" id="new-source">
|
197
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/inserter.rb, line 18</span>
|
198
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>={})
|
199
|
+
<span class="ruby-ivar">@infile</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:infile</span>]
|
200
|
+
<span class="ruby-ivar">@outfile</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:outfile</span>]
|
201
|
+
<span class="ruby-ivar">@insert</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:insert</span>]
|
202
|
+
<span class="ruby-ivar">@position</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:position</span>] <span class="ruby-operator">||</span> <span class="ruby-string">'top'</span>
|
203
|
+
<span class="ruby-keyword">end</span></pre>
|
204
|
+
</div>
|
205
|
+
|
206
|
+
</div>
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
</div>
|
212
|
+
|
213
|
+
|
214
|
+
</section>
|
215
|
+
|
216
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
217
|
+
<header>
|
218
|
+
<h3>Public Instance Methods</h3>
|
219
|
+
</header>
|
220
|
+
|
221
|
+
|
222
|
+
<div id="method-i-execute" class="method-detail ">
|
223
|
+
|
224
|
+
<div class="method-heading">
|
225
|
+
<span class="method-name">execute</span><span
|
226
|
+
class="method-args">()</span>
|
227
|
+
|
228
|
+
<span class="method-click-advice">click to toggle source</span>
|
229
|
+
|
230
|
+
</div>
|
231
|
+
|
232
|
+
|
233
|
+
<div class="method-description">
|
234
|
+
|
235
|
+
<p>Inserts the content of the insert-file at the specified positions (top or
|
236
|
+
bottom)</p>
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
<div class="method-source-code" id="execute-source">
|
242
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/inserter.rb, line 26</span>
|
243
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">execute</span>
|
244
|
+
<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>
|
245
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">position</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-operator">==</span> <span class="ruby-string">'bottom'</span>
|
246
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">infile</span>)
|
247
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">insert</span>)
|
248
|
+
<span class="ruby-keyword">else</span>
|
249
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">insert</span>)
|
250
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">infile</span>)
|
251
|
+
<span class="ruby-keyword">end</span>
|
252
|
+
<span class="ruby-keyword">end</span>
|
253
|
+
<span class="ruby-keyword">end</span></pre>
|
254
|
+
</div>
|
255
|
+
|
256
|
+
</div>
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
</div>
|
262
|
+
|
263
|
+
|
264
|
+
</section>
|
265
|
+
|
266
|
+
</section>
|
267
|
+
</main>
|
268
|
+
|
269
|
+
|
270
|
+
<footer id="validator-badges" role="contentinfo">
|
271
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
272
|
+
<p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.1.
|
273
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
274
|
+
</footer>
|
275
|
+
|
@@ -161,6 +161,19 @@
|
|
161
161
|
</div>
|
162
162
|
</div>
|
163
163
|
|
164
|
+
<div id="attribute-i-script_type" class="method-detail">
|
165
|
+
<div class="method-heading attribute-method-heading">
|
166
|
+
<span class="method-name">script_type</span><span
|
167
|
+
class="attribute-access-type">[R]</span>
|
168
|
+
</div>
|
169
|
+
|
170
|
+
<div class="method-description">
|
171
|
+
|
172
|
+
<p>type of the script-file</p>
|
173
|
+
|
174
|
+
</div>
|
175
|
+
</div>
|
176
|
+
|
164
177
|
</section>
|
165
178
|
|
166
179
|
|
@@ -190,11 +203,12 @@
|
|
190
203
|
|
191
204
|
|
192
205
|
<div class="method-source-code" id="new-source">
|
193
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/script_creator.rb, line
|
206
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/script_creator.rb, line 19</span>
|
194
207
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>={})
|
195
208
|
<span class="ruby-ivar">@dir</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:dir</span>], <span class="ruby-string">'scripts'</span>)
|
196
209
|
<span class="ruby-ivar">@script_name</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:script</span>]
|
197
|
-
<span class="ruby-ivar">@
|
210
|
+
<span class="ruby-ivar">@script_type</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-ivar">@script_name</span>)
|
211
|
+
<span class="ruby-ivar">@method_name</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:method</span>] <span class="ruby-keyword">if</span> <span class="ruby-ivar">@script_type</span> <span class="ruby-operator">==</span> <span class="ruby-string">'.rb'</span>
|
198
212
|
<span class="ruby-identifier">create_script</span>
|
199
213
|
<span class="ruby-keyword">end</span></pre>
|
200
214
|
</div>
|
@@ -200,8 +200,12 @@ href="ScriptList.html#attribute-i-show_methods">#show_methods</a></p>
|
|
200
200
|
<pre><span class="ruby-comment"># File lib/sycsvpro/script_list.rb, line 18</span>
|
201
201
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>={})
|
202
202
|
<span class="ruby-ivar">@script_dir</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:dir</span>]
|
203
|
-
<span class="ruby-ivar">@
|
204
|
-
<span class="ruby-ivar">@
|
203
|
+
<span class="ruby-ivar">@script_type</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:type</span>] <span class="ruby-operator">||</span> <span class="ruby-string">'script'</span>
|
204
|
+
<span class="ruby-ivar">@script_type</span>.<span class="ruby-identifier">downcase!</span>
|
205
|
+
<span class="ruby-ivar">@script_file</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:script</span>] <span class="ruby-operator">||</span> <span class="ruby-string">'*.rb'</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@script_type</span> <span class="ruby-operator">==</span> <span class="ruby-string">'script'</span>
|
206
|
+
<span class="ruby-ivar">@script_file</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:script</span>] <span class="ruby-operator">||</span> <span class="ruby-string">'*.ins'</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@script_type</span> <span class="ruby-operator">==</span> <span class="ruby-string">'insert'</span>
|
207
|
+
<span class="ruby-ivar">@show_methods</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:show_methods</span>] <span class="ruby-keyword">if</span> <span class="ruby-ivar">@script_type</span> <span class="ruby-operator">==</span> <span class="ruby-string">'script'</span>
|
208
|
+
<span class="ruby-ivar">@show_methods</span> = <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@script_type</span> <span class="ruby-operator">==</span> <span class="ruby-string">'insert'</span>
|
205
209
|
<span class="ruby-ivar">@list</span> = {}
|
206
210
|
<span class="ruby-keyword">end</span></pre>
|
207
211
|
</div>
|
@@ -242,7 +246,7 @@ directory</p>
|
|
242
246
|
|
243
247
|
|
244
248
|
<div class="method-source-code" id="execute-source">
|
245
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/script_list.rb, line
|
249
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/script_list.rb, line 30</span>
|
246
250
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">execute</span>
|
247
251
|
<span class="ruby-identifier">scripts</span> = <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">glob</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@script_dir</span>, <span class="ruby-ivar">@script_file</span>))
|
248
252
|
<span class="ruby-identifier">scripts</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">script</span><span class="ruby-operator">|</span>
|
@@ -0,0 +1,323 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class Sycsvpro::Sorter - Your application title</title>
|
8
|
+
|
9
|
+
<link href="../fonts.css" rel="stylesheet">
|
10
|
+
<link href="../rdoc.css" rel="stylesheet">
|
11
|
+
|
12
|
+
<script type="text/javascript">
|
13
|
+
var rdoc_rel_prefix = "../";
|
14
|
+
</script>
|
15
|
+
|
16
|
+
<script src="../js/jquery.js"></script>
|
17
|
+
<script src="../js/navigation.js"></script>
|
18
|
+
<script src="../js/search_index.js"></script>
|
19
|
+
<script src="../js/search.js"></script>
|
20
|
+
<script src="../js/searcher.js"></script>
|
21
|
+
<script src="../js/darkfish.js"></script>
|
22
|
+
|
23
|
+
|
24
|
+
<body id="top" role="document" class="class">
|
25
|
+
<nav role="navigation">
|
26
|
+
<div id="project-navigation">
|
27
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
28
|
+
<h2>
|
29
|
+
<a href="../index.html" rel="home">Home</a>
|
30
|
+
</h2>
|
31
|
+
|
32
|
+
<div id="table-of-contents-navigation">
|
33
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
34
|
+
<a href="../table_of_contents.html#classes">Classes</a>
|
35
|
+
<a href="../table_of_contents.html#methods">Methods</a>
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
40
|
+
<form action="#" method="get" accept-charset="utf-8">
|
41
|
+
<div id="search-field-wrapper">
|
42
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
43
|
+
aria-autocomplete="list" aria-controls="search-results"
|
44
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
45
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<ul id="search-results" aria-label="Search Results"
|
49
|
+
aria-busy="false" aria-expanded="false"
|
50
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
51
|
+
</form>
|
52
|
+
</div>
|
53
|
+
|
54
|
+
</div>
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
<div id="class-metadata">
|
59
|
+
|
60
|
+
<div id="parent-class-section" class="nav-section">
|
61
|
+
<h3>Parent</h3>
|
62
|
+
|
63
|
+
|
64
|
+
<p class="link"><a href="../Object.html">Object</a>
|
65
|
+
|
66
|
+
</div>
|
67
|
+
|
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
|
+
|
80
|
+
|
81
|
+
<!-- Method Quickref -->
|
82
|
+
<div id="method-list-section" class="nav-section">
|
83
|
+
<h3>Methods</h3>
|
84
|
+
|
85
|
+
<ul class="link-list" role="directory">
|
86
|
+
|
87
|
+
<li ><a href="#method-c-new">::new</a>
|
88
|
+
|
89
|
+
<li ><a href="#method-i-execute">#execute</a>
|
90
|
+
|
91
|
+
</ul>
|
92
|
+
</div>
|
93
|
+
|
94
|
+
</div>
|
95
|
+
</nav>
|
96
|
+
|
97
|
+
<main role="main" aria-labelledby="class-Sycsvpro::Sorter">
|
98
|
+
<h1 id="class-Sycsvpro::Sorter" class="class">
|
99
|
+
class Sycsvpro::Sorter
|
100
|
+
</h1>
|
101
|
+
|
102
|
+
<section class="description">
|
103
|
+
|
104
|
+
<p>Sorts an input file based on a column sort filter</p>
|
105
|
+
|
106
|
+
</section>
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
<section class="attribute-method-details" class="method-section">
|
120
|
+
<header>
|
121
|
+
<h3>Attributes</h3>
|
122
|
+
</header>
|
123
|
+
|
124
|
+
|
125
|
+
<div id="attribute-i-col_type_filter" class="method-detail">
|
126
|
+
<div class="method-heading attribute-method-heading">
|
127
|
+
<span class="method-name">col_type_filter</span><span
|
128
|
+
class="attribute-access-type">[R]</span>
|
129
|
+
</div>
|
130
|
+
|
131
|
+
<div class="method-description">
|
132
|
+
|
133
|
+
<p>column type filter</p>
|
134
|
+
|
135
|
+
</div>
|
136
|
+
</div>
|
137
|
+
|
138
|
+
<div id="attribute-i-desc" class="method-detail">
|
139
|
+
<div class="method-heading attribute-method-heading">
|
140
|
+
<span class="method-name">desc</span><span
|
141
|
+
class="attribute-access-type">[R]</span>
|
142
|
+
</div>
|
143
|
+
|
144
|
+
<div class="method-description">
|
145
|
+
|
146
|
+
<p>sort order descending or ascending</p>
|
147
|
+
|
148
|
+
</div>
|
149
|
+
</div>
|
150
|
+
|
151
|
+
<div id="attribute-i-infile" class="method-detail">
|
152
|
+
<div class="method-heading attribute-method-heading">
|
153
|
+
<span class="method-name">infile</span><span
|
154
|
+
class="attribute-access-type">[R]</span>
|
155
|
+
</div>
|
156
|
+
|
157
|
+
<div class="method-description">
|
158
|
+
|
159
|
+
<p>file of the data to sort</p>
|
160
|
+
|
161
|
+
</div>
|
162
|
+
</div>
|
163
|
+
|
164
|
+
<div id="attribute-i-outfile" class="method-detail">
|
165
|
+
<div class="method-heading attribute-method-heading">
|
166
|
+
<span class="method-name">outfile</span><span
|
167
|
+
class="attribute-access-type">[R]</span>
|
168
|
+
</div>
|
169
|
+
|
170
|
+
<div class="method-description">
|
171
|
+
|
172
|
+
<p>file to write the sorted data to</p>
|
173
|
+
|
174
|
+
</div>
|
175
|
+
</div>
|
176
|
+
|
177
|
+
<div id="attribute-i-row_filter" class="method-detail">
|
178
|
+
<div class="method-heading attribute-method-heading">
|
179
|
+
<span class="method-name">row_filter</span><span
|
180
|
+
class="attribute-access-type">[R]</span>
|
181
|
+
</div>
|
182
|
+
|
183
|
+
<div class="method-description">
|
184
|
+
|
185
|
+
<p>row filter</p>
|
186
|
+
|
187
|
+
</div>
|
188
|
+
</div>
|
189
|
+
|
190
|
+
<div id="attribute-i-sorted_rows" class="method-detail">
|
191
|
+
<div class="method-heading attribute-method-heading">
|
192
|
+
<span class="method-name">sorted_rows</span><span
|
193
|
+
class="attribute-access-type">[R]</span>
|
194
|
+
</div>
|
195
|
+
|
196
|
+
<div class="method-description">
|
197
|
+
|
198
|
+
<p>sorted rows</p>
|
199
|
+
|
200
|
+
</div>
|
201
|
+
</div>
|
202
|
+
|
203
|
+
</section>
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
|
208
|
+
<header>
|
209
|
+
<h3>Public Class Methods</h3>
|
210
|
+
</header>
|
211
|
+
|
212
|
+
|
213
|
+
<div id="method-c-new" class="method-detail ">
|
214
|
+
|
215
|
+
<div class="method-heading">
|
216
|
+
<span class="method-name">new</span><span
|
217
|
+
class="method-args">(options={})</span>
|
218
|
+
|
219
|
+
<span class="method-click-advice">click to toggle source</span>
|
220
|
+
|
221
|
+
</div>
|
222
|
+
|
223
|
+
|
224
|
+
<div class="method-description">
|
225
|
+
|
226
|
+
<p>Creates a <a href="Sorter.html">Sorter</a> and takes as options infile,
|
227
|
+
outfile, rows, cols including types and a date format for the date columns
|
228
|
+
to sort (optional)</p>
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
<div class="method-source-code" id="new-source">
|
234
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/sorter.rb, line 28</span>
|
235
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>={})
|
236
|
+
<span class="ruby-ivar">@infile</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:infile</span>]
|
237
|
+
<span class="ruby-ivar">@outfile</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:outfile</span>]
|
238
|
+
<span class="ruby-ivar">@desc</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:desc</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword">false</span>
|
239
|
+
<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>])
|
240
|
+
<span class="ruby-ivar">@col_type_filter</span> = <span class="ruby-constant">ColumnTypeFilter</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>])
|
241
|
+
<span class="ruby-ivar">@sorted_rows</span> = []
|
242
|
+
<span class="ruby-keyword">end</span></pre>
|
243
|
+
</div>
|
244
|
+
|
245
|
+
</div>
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
</div>
|
251
|
+
|
252
|
+
|
253
|
+
</section>
|
254
|
+
|
255
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
256
|
+
<header>
|
257
|
+
<h3>Public Instance Methods</h3>
|
258
|
+
</header>
|
259
|
+
|
260
|
+
|
261
|
+
<div id="method-i-execute" class="method-detail ">
|
262
|
+
|
263
|
+
<div class="method-heading">
|
264
|
+
<span class="method-name">execute</span><span
|
265
|
+
class="method-args">()</span>
|
266
|
+
|
267
|
+
<span class="method-click-advice">click to toggle source</span>
|
268
|
+
|
269
|
+
</div>
|
270
|
+
|
271
|
+
|
272
|
+
<div class="method-description">
|
273
|
+
|
274
|
+
<p>Sorts the data of the infile</p>
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
<div class="method-source-code" id="execute-source">
|
280
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/sorter.rb, line 38</span>
|
281
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">execute</span>
|
282
|
+
<span class="ruby-identifier">rows</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">readlines</span>(<span class="ruby-identifier">infile</span>)
|
283
|
+
|
284
|
+
<span class="ruby-identifier">rows</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>
|
285
|
+
<span class="ruby-identifier">filtered</span> = <span class="ruby-identifier">col_type_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">row</span><span class="ruby-operator">:</span> <span class="ruby-identifier">index</span>))
|
286
|
+
<span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">filtered</span>.<span class="ruby-identifier">nil?</span>
|
287
|
+
<span class="ruby-identifier">sorted_rows</span> <span class="ruby-operator"><<</span> (<span class="ruby-identifier">filtered</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">index</span>)
|
288
|
+
<span class="ruby-keyword">end</span>
|
289
|
+
|
290
|
+
<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>
|
291
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">desc</span>
|
292
|
+
<span class="ruby-identifier">sorted_rows</span>.<span class="ruby-identifier">compact</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
|
293
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">unstring</span>(<span class="ruby-identifier">rows</span>[<span class="ruby-identifier">row</span>.<span class="ruby-identifier">last</span>])
|
294
|
+
<span class="ruby-keyword">end</span>
|
295
|
+
<span class="ruby-keyword">else</span>
|
296
|
+
<span class="ruby-identifier">sorted_rows</span>.<span class="ruby-identifier">compact</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">row</span><span class="ruby-operator">|</span>
|
297
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">unstring</span>(<span class="ruby-identifier">rows</span>[<span class="ruby-identifier">row</span>.<span class="ruby-identifier">last</span>])
|
298
|
+
<span class="ruby-keyword">end</span>
|
299
|
+
<span class="ruby-keyword">end</span>
|
300
|
+
<span class="ruby-keyword">end</span>
|
301
|
+
<span class="ruby-keyword">end</span></pre>
|
302
|
+
</div>
|
303
|
+
|
304
|
+
</div>
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
</div>
|
310
|
+
|
311
|
+
|
312
|
+
</section>
|
313
|
+
|
314
|
+
</section>
|
315
|
+
</main>
|
316
|
+
|
317
|
+
|
318
|
+
<footer id="validator-badges" role="contentinfo">
|
319
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
320
|
+
<p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.1.
|
321
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
322
|
+
</footer>
|
323
|
+
|