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
data/html/Sycsvpro.html
CHANGED
data/html/created.rid
CHANGED
@@ -1,20 +1,23 @@
|
|
1
|
-
|
2
|
-
README.rdoc Sun,
|
3
|
-
lib/sycsvpro.rb
|
1
|
+
Wed, 26 Feb 2014 22:34:31 +0100
|
2
|
+
README.rdoc Sun, 23 Feb 2014 19:23:16 +0100
|
3
|
+
lib/sycsvpro.rb Wed, 26 Feb 2014 20:27:40 +0100
|
4
4
|
lib/sycsvpro/allocator.rb Wed, 19 Feb 2014 20:34:28 +0100
|
5
5
|
lib/sycsvpro/analyzer.rb Tue, 18 Feb 2014 19:57:28 +0100
|
6
6
|
lib/sycsvpro/calculator.rb Tue, 18 Feb 2014 19:53:34 +0100
|
7
7
|
lib/sycsvpro/collector.rb Sun, 16 Feb 2014 20:59:27 +0100
|
8
|
-
lib/sycsvpro/column_filter.rb
|
8
|
+
lib/sycsvpro/column_filter.rb Tue, 25 Feb 2014 20:21:09 +0100
|
9
|
+
lib/sycsvpro/column_type_filter.rb Wed, 26 Feb 2014 22:28:42 +0100
|
9
10
|
lib/sycsvpro/counter.rb Fri, 21 Feb 2014 21:11:49 +0100
|
10
11
|
lib/sycsvpro/dsl.rb Tue, 18 Feb 2014 21:34:51 +0100
|
11
12
|
lib/sycsvpro/extractor.rb Sat, 22 Feb 2014 17:58:18 +0100
|
12
|
-
lib/sycsvpro/filter.rb Tue,
|
13
|
+
lib/sycsvpro/filter.rb Tue, 25 Feb 2014 21:18:25 +0100
|
13
14
|
lib/sycsvpro/header.rb Tue, 18 Feb 2014 19:50:26 +0100
|
15
|
+
lib/sycsvpro/inserter.rb Tue, 25 Feb 2014 22:40:30 +0100
|
14
16
|
lib/sycsvpro/mapper.rb Tue, 18 Feb 2014 19:45:47 +0100
|
15
17
|
lib/sycsvpro/profiler.rb Sun, 16 Feb 2014 21:31:39 +0100
|
16
18
|
lib/sycsvpro/row_filter.rb Tue, 18 Feb 2014 19:45:25 +0100
|
17
|
-
lib/sycsvpro/script_creator.rb
|
18
|
-
lib/sycsvpro/script_list.rb Sun, 23 Feb 2014
|
19
|
-
lib/sycsvpro/
|
20
|
-
|
19
|
+
lib/sycsvpro/script_creator.rb Sun, 23 Feb 2014 20:35:21 +0100
|
20
|
+
lib/sycsvpro/script_list.rb Sun, 23 Feb 2014 21:03:22 +0100
|
21
|
+
lib/sycsvpro/sorter.rb Wed, 26 Feb 2014 08:56:58 +0100
|
22
|
+
lib/sycsvpro/version.rb Sun, 23 Feb 2014 13:57:16 +0100
|
23
|
+
bin/sycsvpro Wed, 26 Feb 2014 21:31:44 +0100
|
data/html/index.html
CHANGED
@@ -86,6 +86,8 @@
|
|
86
86
|
|
87
87
|
<li><a href="./Sycsvpro/ColumnFilter.html">Sycsvpro::ColumnFilter</a>
|
88
88
|
|
89
|
+
<li><a href="./Sycsvpro/ColumnTypeFilter.html">Sycsvpro::ColumnTypeFilter</a>
|
90
|
+
|
89
91
|
<li><a href="./Sycsvpro/Counter.html">Sycsvpro::Counter</a>
|
90
92
|
|
91
93
|
<li><a href="./Sycsvpro/Extractor.html">Sycsvpro::Extractor</a>
|
@@ -94,6 +96,8 @@
|
|
94
96
|
|
95
97
|
<li><a href="./Sycsvpro/Header.html">Sycsvpro::Header</a>
|
96
98
|
|
99
|
+
<li><a href="./Sycsvpro/Inserter.html">Sycsvpro::Inserter</a>
|
100
|
+
|
97
101
|
<li><a href="./Sycsvpro/Mapper.html">Sycsvpro::Mapper</a>
|
98
102
|
|
99
103
|
<li><a href="./Sycsvpro/Profiler.html">Sycsvpro::Profiler</a>
|
@@ -104,6 +108,8 @@
|
|
104
108
|
|
105
109
|
<li><a href="./Sycsvpro/ScriptList.html">Sycsvpro::ScriptList</a>
|
106
110
|
|
111
|
+
<li><a href="./Sycsvpro/Sorter.html">Sycsvpro::Sorter</a>
|
112
|
+
|
107
113
|
</ul>
|
108
114
|
</div>
|
109
115
|
|
@@ -129,6 +135,9 @@ href="mailto:pierre@sugaryourcoffee.de">pierre@sugaryourcoffee.de</a>)</p>
|
|
129
135
|
<p>The application provides an interface for analyzing, cleaning and operating
|
130
136
|
on csv files</p>
|
131
137
|
|
138
|
+
<p><a href="http://badge.fury.io/rb/sycsvpro"><img
|
139
|
+
src="https://badge.fury.io/rb/sycsvpro.png" alt="Gem Version" /></a></p>
|
140
|
+
|
132
141
|
<h2 id="label-Install">Install<span><a href="#label-Install">¶</a> <a href="#documentation">↑</a></span></h2>
|
133
142
|
|
134
143
|
<p>Install:</p>
|
@@ -174,7 +183,7 @@ bin</pre>
|
|
174
183
|
|
175
184
|
<p>VERSION</p>
|
176
185
|
|
177
|
-
<pre>0.0.
|
186
|
+
<pre>0.0.8</pre>
|
178
187
|
|
179
188
|
<p>GLOBAL OPTIONS</p>
|
180
189
|
|
@@ -196,7 +205,10 @@ count - Counts the occurences of column values. Uses column values as heading
|
|
196
205
|
execute - Executes the code provided in a file
|
197
206
|
extract - Extract specified rows and columns from the file
|
198
207
|
help - Shows a list of commands or help for one command
|
199
|
-
|
208
|
+
insert - Inserts rows from a file to a csv-file
|
209
|
+
list - List scripts in the scripts directory with optionally listing methods
|
210
|
+
map - Map values in columns to new values
|
211
|
+
sort - Sort columns based on column values</pre>
|
200
212
|
</main>
|
201
213
|
|
202
214
|
|
data/html/js/search_index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var search_data = {"index":{"searchIndex":["dsl","object","sycsvpro","allocator","analyzer","calculator","collector","columnfilter","counter","extractor","filter","header","mapper","profiler","rowfilter","scriptcreator","scriptlist","execute()","execute()","execute()","execute()","execute()","execute()","execute()","execute()","has_filter?()","method_missing()","method_missing()","new()","new()","new()","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::allocator","sycsvpro::analyzer","sycsvpro::calculator","sycsvpro::collector","sycsvpro::columnfilter","sycsvpro::counter","sycsvpro::extractor","sycsvpro::filter","sycsvpro::header","sycsvpro::mapper","sycsvpro::profiler","sycsvpro::rowfilter","sycsvpro::scriptcreator","sycsvpro::scriptlist","sycsvpro::allocator#execute()","sycsvpro::calculator#execute()","sycsvpro::collector#execute()","sycsvpro::counter#execute()","sycsvpro::extractor#execute()","sycsvpro::mapper#execute()","sycsvpro::profiler#execute()","sycsvpro::scriptlist#execute()","sycsvpro::filter#has_filter?()","sycsvpro::calculator#method_missing()","sycsvpro::filter#method_missing()","sycsvpro::allocator::new()","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::scriptcreator::new()","sycsvpro::scriptlist::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::Allocator","","Sycsvpro/Allocator.html","","<p>Allocates columns to a key column\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"],["Sycsvpro::ScriptCreator","","Sycsvpro/ScriptCreator.html","","<p>Creates a ruby script scaffold\n"],["Sycsvpro::ScriptList","","Sycsvpro/ScriptList.html","","<p>Lists the contents of the script directory. Optionally listing a specific\nscript file and also optionally …\n"],["execute","Sycsvpro::Allocator","Sycsvpro/Allocator.html#method-i-execute","()","<p>Executes the allocator and assigns column values to the key\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"],["execute","Sycsvpro::ScriptList","Sycsvpro/ScriptList.html#method-i-execute","()","<p>Retrieves the information about scripts and methods from the script\ndirectory\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::Allocator","Sycsvpro/Allocator.html#method-c-new","(options={})","<p>Creates a new allocator. Options are infile, outfile, key, rows and columns\nto allocate to key\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. Takes as attributes infile, outfile, key, rows,\ncols, date-format and indicator …\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"],["new","Sycsvpro::ScriptCreator","Sycsvpro/ScriptCreator.html#method-c-new","(options={})","<p>Creates a new ScriptCreator\n"],["new","Sycsvpro::ScriptList","Sycsvpro/ScriptList.html#method-c-new","(options={})","<p>Creates a new ScriptList. Takes params script_dir, script_file and\nshow_methods\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"]]}}
|
1
|
+
var search_data = {"index":{"searchIndex":["dsl","object","sycsvpro","allocator","analyzer","calculator","collector","columnfilter","columntypefilter","counter","extractor","filter","header","inserter","mapper","profiler","rowfilter","scriptcreator","scriptlist","sorter","execute()","execute()","execute()","execute()","execute()","execute()","execute()","execute()","execute()","execute()","has_filter?()","method_missing()","method_missing()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","pivot_each_column()","process()","process()","process()","process()","process()","process_file()","result()","rows()","unstring()","write_result()","write_to()","readme"],"longSearchIndex":["dsl","object","sycsvpro","sycsvpro::allocator","sycsvpro::analyzer","sycsvpro::calculator","sycsvpro::collector","sycsvpro::columnfilter","sycsvpro::columntypefilter","sycsvpro::counter","sycsvpro::extractor","sycsvpro::filter","sycsvpro::header","sycsvpro::inserter","sycsvpro::mapper","sycsvpro::profiler","sycsvpro::rowfilter","sycsvpro::scriptcreator","sycsvpro::scriptlist","sycsvpro::sorter","sycsvpro::allocator#execute()","sycsvpro::calculator#execute()","sycsvpro::collector#execute()","sycsvpro::counter#execute()","sycsvpro::extractor#execute()","sycsvpro::inserter#execute()","sycsvpro::mapper#execute()","sycsvpro::profiler#execute()","sycsvpro::scriptlist#execute()","sycsvpro::sorter#execute()","sycsvpro::filter#has_filter?()","sycsvpro::calculator#method_missing()","sycsvpro::filter#method_missing()","sycsvpro::allocator::new()","sycsvpro::analyzer::new()","sycsvpro::calculator::new()","sycsvpro::collector::new()","sycsvpro::counter::new()","sycsvpro::extractor::new()","sycsvpro::filter::new()","sycsvpro::header::new()","sycsvpro::inserter::new()","sycsvpro::mapper::new()","sycsvpro::profiler::new()","sycsvpro::scriptcreator::new()","sycsvpro::scriptlist::new()","sycsvpro::sorter::new()","sycsvpro::filter#pivot_each_column()","sycsvpro::columnfilter#process()","sycsvpro::columntypefilter#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::Allocator","","Sycsvpro/Allocator.html","","<p>Allocates columns to a key column\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::ColumnTypeFilter","","Sycsvpro/ColumnTypeFilter.html","","<p>Create a filter based on a colum and its type\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::Inserter","","Sycsvpro/Inserter.html","","<p>Insert a text file into another textfile at a specified position\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"],["Sycsvpro::ScriptCreator","","Sycsvpro/ScriptCreator.html","","<p>Creates a ruby script scaffold\n"],["Sycsvpro::ScriptList","","Sycsvpro/ScriptList.html","","<p>Lists the contents of the script directory. Optionally listing a specific\nscript file and also optionally …\n"],["Sycsvpro::Sorter","","Sycsvpro/Sorter.html","","<p>Sorts an input file based on a column sort filter\n"],["execute","Sycsvpro::Allocator","Sycsvpro/Allocator.html#method-i-execute","()","<p>Executes the allocator and assigns column values to the key\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::Inserter","Sycsvpro/Inserter.html#method-i-execute","()","<p>Inserts the content of the insert-file at the specified positions (top or\nbottom)\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"],["execute","Sycsvpro::ScriptList","Sycsvpro/ScriptList.html#method-i-execute","()","<p>Retrieves the information about scripts and methods from the script\ndirectory\n"],["execute","Sycsvpro::Sorter","Sycsvpro/Sorter.html#method-i-execute","()","<p>Sorts the data of the infile\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::Allocator","Sycsvpro/Allocator.html#method-c-new","(options={})","<p>Creates a new allocator. Options are infile, outfile, key, rows and columns\nto allocate to key\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. Takes as attributes infile, outfile, key, rows,\ncols, date-format and indicator …\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::Inserter","Sycsvpro/Inserter.html#method-c-new","(options={})","<p>Creates an Inserter and takes options infile, outfile, insert-file and\nposition where to insert the insert-file …\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"],["new","Sycsvpro::ScriptCreator","Sycsvpro/ScriptCreator.html#method-c-new","(options={})","<p>Creates a new ScriptCreator\n"],["new","Sycsvpro::ScriptList","Sycsvpro/ScriptList.html#method-c-new","(options={})","<p>Creates a new ScriptList. Takes params script_dir, script_file and\nshow_methods\n"],["new","Sycsvpro::Sorter","Sycsvpro/Sorter.html#method-c-new","(options={})","<p>Creates a Sorter and takes as options infile, outfile, rows, cols including\ntypes and a date format for …\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::ColumnTypeFilter","Sycsvpro/ColumnTypeFilter.html#method-i-process","(object, options={})","<p>Processes the filter and returns the filtered columns\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
@@ -67,6 +67,9 @@
|
|
67
67
|
<li class="class">
|
68
68
|
<a href="Sycsvpro/ColumnFilter.html">Sycsvpro::ColumnFilter</a>
|
69
69
|
</li>
|
70
|
+
<li class="class">
|
71
|
+
<a href="Sycsvpro/ColumnTypeFilter.html">Sycsvpro::ColumnTypeFilter</a>
|
72
|
+
</li>
|
70
73
|
<li class="class">
|
71
74
|
<a href="Sycsvpro/Counter.html">Sycsvpro::Counter</a>
|
72
75
|
</li>
|
@@ -79,6 +82,9 @@
|
|
79
82
|
<li class="class">
|
80
83
|
<a href="Sycsvpro/Header.html">Sycsvpro::Header</a>
|
81
84
|
</li>
|
85
|
+
<li class="class">
|
86
|
+
<a href="Sycsvpro/Inserter.html">Sycsvpro::Inserter</a>
|
87
|
+
</li>
|
82
88
|
<li class="class">
|
83
89
|
<a href="Sycsvpro/Mapper.html">Sycsvpro::Mapper</a>
|
84
90
|
</li>
|
@@ -94,6 +100,9 @@
|
|
94
100
|
<li class="class">
|
95
101
|
<a href="Sycsvpro/ScriptList.html">Sycsvpro::ScriptList</a>
|
96
102
|
</li>
|
103
|
+
<li class="class">
|
104
|
+
<a href="Sycsvpro/Sorter.html">Sycsvpro::Sorter</a>
|
105
|
+
</li>
|
97
106
|
</ul>
|
98
107
|
|
99
108
|
<h2 id="methods">Methods</h2>
|
@@ -125,14 +134,14 @@
|
|
125
134
|
<span class="container">Sycsvpro::Calculator</span>
|
126
135
|
|
127
136
|
<li class="method">
|
128
|
-
<a href="Sycsvpro/
|
137
|
+
<a href="Sycsvpro/Inserter.html#method-c-new">::new</a>
|
129
138
|
—
|
130
|
-
<span class="container">Sycsvpro::
|
139
|
+
<span class="container">Sycsvpro::Inserter</span>
|
131
140
|
|
132
141
|
<li class="method">
|
133
|
-
<a href="Sycsvpro/
|
142
|
+
<a href="Sycsvpro/Header.html#method-c-new">::new</a>
|
134
143
|
—
|
135
|
-
<span class="container">Sycsvpro::
|
144
|
+
<span class="container">Sycsvpro::Header</span>
|
136
145
|
|
137
146
|
<li class="method">
|
138
147
|
<a href="Sycsvpro/Collector.html#method-c-new">::new</a>
|
@@ -140,14 +149,19 @@
|
|
140
149
|
<span class="container">Sycsvpro::Collector</span>
|
141
150
|
|
142
151
|
<li class="method">
|
143
|
-
<a href="Sycsvpro/
|
152
|
+
<a href="Sycsvpro/ScriptList.html#method-c-new">::new</a>
|
144
153
|
—
|
145
|
-
<span class="container">Sycsvpro::
|
154
|
+
<span class="container">Sycsvpro::ScriptList</span>
|
146
155
|
|
147
156
|
<li class="method">
|
148
|
-
<a href="Sycsvpro/
|
157
|
+
<a href="Sycsvpro/Filter.html#method-c-new">::new</a>
|
149
158
|
—
|
150
|
-
<span class="container">Sycsvpro::
|
159
|
+
<span class="container">Sycsvpro::Filter</span>
|
160
|
+
|
161
|
+
<li class="method">
|
162
|
+
<a href="Sycsvpro/Sorter.html#method-c-new">::new</a>
|
163
|
+
—
|
164
|
+
<span class="container">Sycsvpro::Sorter</span>
|
151
165
|
|
152
166
|
<li class="method">
|
153
167
|
<a href="Sycsvpro/Counter.html#method-c-new">::new</a>
|
@@ -155,34 +169,34 @@
|
|
155
169
|
<span class="container">Sycsvpro::Counter</span>
|
156
170
|
|
157
171
|
<li class="method">
|
158
|
-
<a href="Sycsvpro/
|
172
|
+
<a href="Sycsvpro/Extractor.html#method-c-new">::new</a>
|
159
173
|
—
|
160
|
-
<span class="container">Sycsvpro::
|
174
|
+
<span class="container">Sycsvpro::Extractor</span>
|
161
175
|
|
162
176
|
<li class="method">
|
163
|
-
<a href="Sycsvpro/
|
177
|
+
<a href="Sycsvpro/ScriptCreator.html#method-c-new">::new</a>
|
164
178
|
—
|
165
|
-
<span class="container">Sycsvpro::
|
179
|
+
<span class="container">Sycsvpro::ScriptCreator</span>
|
166
180
|
|
167
181
|
<li class="method">
|
168
|
-
<a href="Sycsvpro/
|
182
|
+
<a href="Sycsvpro/ScriptList.html#method-i-execute">#execute</a>
|
169
183
|
—
|
170
|
-
<span class="container">Sycsvpro::
|
184
|
+
<span class="container">Sycsvpro::ScriptList</span>
|
171
185
|
|
172
186
|
<li class="method">
|
173
|
-
<a href="Sycsvpro/
|
187
|
+
<a href="Sycsvpro/Counter.html#method-i-execute">#execute</a>
|
174
188
|
—
|
175
|
-
<span class="container">Sycsvpro::
|
189
|
+
<span class="container">Sycsvpro::Counter</span>
|
176
190
|
|
177
191
|
<li class="method">
|
178
|
-
<a href="Sycsvpro/
|
192
|
+
<a href="Sycsvpro/Profiler.html#method-i-execute">#execute</a>
|
179
193
|
—
|
180
|
-
<span class="container">Sycsvpro::
|
194
|
+
<span class="container">Sycsvpro::Profiler</span>
|
181
195
|
|
182
196
|
<li class="method">
|
183
|
-
<a href="Sycsvpro/
|
197
|
+
<a href="Sycsvpro/Allocator.html#method-i-execute">#execute</a>
|
184
198
|
—
|
185
|
-
<span class="container">Sycsvpro::
|
199
|
+
<span class="container">Sycsvpro::Allocator</span>
|
186
200
|
|
187
201
|
<li class="method">
|
188
202
|
<a href="Sycsvpro/Mapper.html#method-i-execute">#execute</a>
|
@@ -190,14 +204,29 @@
|
|
190
204
|
<span class="container">Sycsvpro::Mapper</span>
|
191
205
|
|
192
206
|
<li class="method">
|
193
|
-
<a href="Sycsvpro/
|
207
|
+
<a href="Sycsvpro/Collector.html#method-i-execute">#execute</a>
|
194
208
|
—
|
195
|
-
<span class="container">Sycsvpro::
|
209
|
+
<span class="container">Sycsvpro::Collector</span>
|
196
210
|
|
197
211
|
<li class="method">
|
198
|
-
<a href="Sycsvpro/
|
212
|
+
<a href="Sycsvpro/Sorter.html#method-i-execute">#execute</a>
|
199
213
|
—
|
200
|
-
<span class="container">Sycsvpro::
|
214
|
+
<span class="container">Sycsvpro::Sorter</span>
|
215
|
+
|
216
|
+
<li class="method">
|
217
|
+
<a href="Sycsvpro/Inserter.html#method-i-execute">#execute</a>
|
218
|
+
—
|
219
|
+
<span class="container">Sycsvpro::Inserter</span>
|
220
|
+
|
221
|
+
<li class="method">
|
222
|
+
<a href="Sycsvpro/Calculator.html#method-i-execute">#execute</a>
|
223
|
+
—
|
224
|
+
<span class="container">Sycsvpro::Calculator</span>
|
225
|
+
|
226
|
+
<li class="method">
|
227
|
+
<a href="Sycsvpro/Extractor.html#method-i-execute">#execute</a>
|
228
|
+
—
|
229
|
+
<span class="container">Sycsvpro::Extractor</span>
|
201
230
|
|
202
231
|
<li class="method">
|
203
232
|
<a href="Sycsvpro/Filter.html#method-i-has_filter-3F">#has_filter?</a>
|
@@ -220,24 +249,29 @@
|
|
220
249
|
<span class="container">Sycsvpro::Filter</span>
|
221
250
|
|
222
251
|
<li class="method">
|
223
|
-
<a href="Sycsvpro/
|
252
|
+
<a href="Sycsvpro/ColumnFilter.html#method-i-process">#process</a>
|
224
253
|
—
|
225
|
-
<span class="container">Sycsvpro::
|
254
|
+
<span class="container">Sycsvpro::ColumnFilter</span>
|
226
255
|
|
227
256
|
<li class="method">
|
228
|
-
<a href="Sycsvpro/
|
257
|
+
<a href="Sycsvpro/ColumnTypeFilter.html#method-i-process">#process</a>
|
229
258
|
—
|
230
|
-
<span class="container">Sycsvpro::
|
259
|
+
<span class="container">Sycsvpro::ColumnTypeFilter</span>
|
231
260
|
|
232
261
|
<li class="method">
|
233
|
-
<a href="Sycsvpro/
|
262
|
+
<a href="Sycsvpro/RowFilter.html#method-i-process">#process</a>
|
234
263
|
—
|
235
|
-
<span class="container">Sycsvpro::
|
264
|
+
<span class="container">Sycsvpro::RowFilter</span>
|
236
265
|
|
237
266
|
<li class="method">
|
238
|
-
<a href="Sycsvpro/
|
267
|
+
<a href="Sycsvpro/Header.html#method-i-process">#process</a>
|
239
268
|
—
|
240
|
-
<span class="container">Sycsvpro::
|
269
|
+
<span class="container">Sycsvpro::Header</span>
|
270
|
+
|
271
|
+
<li class="method">
|
272
|
+
<a href="Sycsvpro/Filter.html#method-i-process">#process</a>
|
273
|
+
—
|
274
|
+
<span class="container">Sycsvpro::Filter</span>
|
241
275
|
|
242
276
|
<li class="method">
|
243
277
|
<a href="Sycsvpro/Counter.html#method-i-process_file">#process_file</a>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Operating csv files
|
2
|
+
module Sycsvpro
|
3
|
+
|
4
|
+
# Create a filter based on a colum and its type
|
5
|
+
class ColumnTypeFilter < ColumnFilter
|
6
|
+
|
7
|
+
# Processes the filter and returns the filtered columns
|
8
|
+
def process(object, options={})
|
9
|
+
filtered = super(object, options)
|
10
|
+
|
11
|
+
return nil if filtered.nil?
|
12
|
+
|
13
|
+
values = filtered.split(';')
|
14
|
+
|
15
|
+
values.each_with_index do |value, index|
|
16
|
+
if types[index] == 'n'
|
17
|
+
if value =~ /\./
|
18
|
+
number_value = value.to_f
|
19
|
+
else
|
20
|
+
number_value = value.to_i
|
21
|
+
end
|
22
|
+
values[index] = number_value
|
23
|
+
elsif types[index] == 'd'
|
24
|
+
if value.empty?
|
25
|
+
date = Date.strptime('9999-9-9', '%Y-%m-%d')
|
26
|
+
else
|
27
|
+
date = Date.strptime(value, date_format)
|
28
|
+
end
|
29
|
+
values[index] = date
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
values
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/sycsvpro/filter.rb
CHANGED
@@ -11,6 +11,8 @@ module Sycsvpro
|
|
11
11
|
attr_reader :date_format
|
12
12
|
# Filter for rows and columns
|
13
13
|
attr_reader :filter
|
14
|
+
# Type of column (n = number, s = string)
|
15
|
+
attr_reader :types
|
14
16
|
# Pattern that is used as a filter
|
15
17
|
attr_reader :pattern
|
16
18
|
# Comparison that is used as a filter
|
@@ -20,6 +22,7 @@ module Sycsvpro
|
|
20
22
|
def initialize(values, options={})
|
21
23
|
@date_format = options[:df] || "%Y-%m-%d"
|
22
24
|
@filter = []
|
25
|
+
@types = []
|
23
26
|
@pattern = []
|
24
27
|
@pivot = {}
|
25
28
|
create_filter(values)
|
@@ -28,7 +31,9 @@ module Sycsvpro
|
|
28
31
|
# Creates the filters based on the given patterns
|
29
32
|
def method_missing(id, *args, &block)
|
30
33
|
return equal($1, args, block) if id =~ /^(\d+)$/
|
34
|
+
return equal_type($1, $2, args, block) if id =~ /^(s|n|d):(\d+)$/
|
31
35
|
return range($1, $2, args, block) if id =~ /^(\d+)-(\d+)$/
|
36
|
+
return range_type($1, $2, $3, args, block) if id =~ /^(s|n|d):(\d+)-(\d+)$/
|
32
37
|
return regex($1, args, block) if id =~ /^\/(.*)\/$/
|
33
38
|
return col_regex($1, $2, args, block) if id =~ /^(\d+):\/(.*)\/$/
|
34
39
|
return date($1, $2, $3, args, block) if id =~ /^(\d+):(<|=|>)(\d+.\d+.\d+)/
|
@@ -72,11 +77,25 @@ module Sycsvpro
|
|
72
77
|
filter << value.to_i unless filter.index(value.to_i)
|
73
78
|
end
|
74
79
|
|
80
|
+
# Adds a single value and an associated type to the filter
|
81
|
+
def equal_type(type, value, args, block)
|
82
|
+
filter_size_before = filter.size
|
83
|
+
equal(value, args, block)
|
84
|
+
types << type if filter_size_before < filter.size
|
85
|
+
end
|
86
|
+
|
75
87
|
# Adds a range to the filter
|
76
88
|
def range(start_value, end_value, args, block)
|
77
89
|
filter << (start_value.to_i..end_value.to_i).to_a
|
78
90
|
end
|
79
91
|
|
92
|
+
# Adds a range and the associated types to the filter
|
93
|
+
def range_type(type, start_value, end_value, args, block)
|
94
|
+
filter_size_before = filter.size
|
95
|
+
range(start_value, end_value, args, block)
|
96
|
+
(filter.size - filter_size_before).times { types << type }
|
97
|
+
end
|
98
|
+
|
80
99
|
# Adds a regex to the pattern filter
|
81
100
|
def regex(value, args, block)
|
82
101
|
pattern << value unless pattern.index(value)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Operating csv files
|
2
|
+
module Sycsvpro
|
3
|
+
|
4
|
+
# Insert a text file into another textfile at a specified position
|
5
|
+
class Inserter
|
6
|
+
|
7
|
+
# file to insert lines to
|
8
|
+
attr_reader :infile
|
9
|
+
# file to write result to
|
10
|
+
attr_reader :outfile
|
11
|
+
# file that contains the lines to insert
|
12
|
+
attr_reader :insert
|
13
|
+
# position (top or bottom) where to insert the rows
|
14
|
+
attr_reader :position
|
15
|
+
|
16
|
+
# Creates an Inserter and takes options infile, outfile, insert-file and position where to
|
17
|
+
# insert the insert-file content. Default position is top
|
18
|
+
def initialize(options={})
|
19
|
+
@infile = options[:infile]
|
20
|
+
@outfile = options[:outfile]
|
21
|
+
@insert = options[:insert]
|
22
|
+
@position = options[:position] || 'top'
|
23
|
+
end
|
24
|
+
|
25
|
+
# Inserts the content of the insert-file at the specified positions (top or bottom)
|
26
|
+
def execute
|
27
|
+
File.open(outfile, 'w') do |out|
|
28
|
+
if position.downcase == 'bottom'
|
29
|
+
out.puts File.read(infile)
|
30
|
+
out.puts File.read(insert)
|
31
|
+
else
|
32
|
+
out.puts File.read(insert)
|
33
|
+
out.puts File.read(infile)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -12,12 +12,15 @@ module Sycsvpro
|
|
12
12
|
attr_reader :method_name
|
13
13
|
# script_file path
|
14
14
|
attr_reader :script_file
|
15
|
+
# type of the script-file
|
16
|
+
attr_reader :script_type
|
15
17
|
|
16
18
|
# Creates a new ScriptCreator
|
17
19
|
def initialize(options={})
|
18
20
|
@dir = File.join(options[:dir], 'scripts')
|
19
21
|
@script_name = options[:script]
|
20
|
-
@
|
22
|
+
@script_type = File.extname(@script_name)
|
23
|
+
@method_name = options[:method] if @script_type == '.rb'
|
21
24
|
create_script
|
22
25
|
end
|
23
26
|
|
@@ -31,12 +34,14 @@ module Sycsvpro
|
|
31
34
|
@script_file = File.join(dir, script_name)
|
32
35
|
unless File.exists? @script_file
|
33
36
|
File.open(@script_file, 'w') do |f|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
if script_type == '.rb'
|
38
|
+
f.print "def "
|
39
|
+
f.puts "#{method_name}" if method_name
|
40
|
+
f.puts "end"
|
41
|
+
end
|
37
42
|
end
|
38
43
|
else
|
39
|
-
if method_name
|
44
|
+
if method_name and script_type == '.rb'
|
40
45
|
File.open(@script_file, 'a') do |f|
|
41
46
|
f.puts
|
42
47
|
f.puts "def #{method_name}"
|
data/lib/sycsvpro/script_list.rb
CHANGED
@@ -17,8 +17,12 @@ module Sycsvpro
|
|
17
17
|
# Creates a new ScriptList. Takes params script_dir, script_file and show_methods
|
18
18
|
def initialize(options={})
|
19
19
|
@script_dir = options[:dir]
|
20
|
-
@
|
21
|
-
@
|
20
|
+
@script_type = options[:type] || 'script'
|
21
|
+
@script_type.downcase!
|
22
|
+
@script_file = options[:script] || '*.rb' if @script_type == 'script'
|
23
|
+
@script_file = options[:script] || '*.ins' if @script_type == 'insert'
|
24
|
+
@show_methods = options[:show_methods] if @script_type == 'script'
|
25
|
+
@show_methods = false if @script_type == 'insert'
|
22
26
|
@list = {}
|
23
27
|
end
|
24
28
|
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative 'row_filter'
|
2
|
+
require_relative 'column_type_filter'
|
3
|
+
require_relative 'dsl'
|
4
|
+
|
5
|
+
# Operating csv files
|
6
|
+
module Sycsvpro
|
7
|
+
|
8
|
+
# Sorts an input file based on a column sort filter
|
9
|
+
class Sorter
|
10
|
+
|
11
|
+
include Dsl
|
12
|
+
|
13
|
+
# file of the data to sort
|
14
|
+
attr_reader :infile
|
15
|
+
# file to write the sorted data to
|
16
|
+
attr_reader :outfile
|
17
|
+
# row filter
|
18
|
+
attr_reader :row_filter
|
19
|
+
# column type filter
|
20
|
+
attr_reader :col_type_filter
|
21
|
+
# sorted rows
|
22
|
+
attr_reader :sorted_rows
|
23
|
+
# sort order descending or ascending
|
24
|
+
attr_reader :desc
|
25
|
+
|
26
|
+
# Creates a Sorter and takes as options infile, outfile, rows, cols including types and a
|
27
|
+
# date format for the date columns to sort (optional)
|
28
|
+
def initialize(options={})
|
29
|
+
@infile = options[:infile]
|
30
|
+
@outfile = options[:outfile]
|
31
|
+
@desc = options[:desc] || false
|
32
|
+
@row_filter = RowFilter.new(options[:rows])
|
33
|
+
@col_type_filter = ColumnTypeFilter.new(options[:cols], df: options[:df])
|
34
|
+
@sorted_rows = []
|
35
|
+
end
|
36
|
+
|
37
|
+
# Sorts the data of the infile
|
38
|
+
def execute
|
39
|
+
rows = File.readlines(infile)
|
40
|
+
|
41
|
+
rows.each_with_index do |line, index|
|
42
|
+
filtered = col_type_filter.process(row_filter.process(line, row: index))
|
43
|
+
next if filtered.nil?
|
44
|
+
sorted_rows << (filtered << index)
|
45
|
+
end
|
46
|
+
|
47
|
+
File.open(outfile, 'w') do |out|
|
48
|
+
if desc
|
49
|
+
sorted_rows.compact.sort.reverse.each do |row|
|
50
|
+
out.puts unstring(rows[row.last])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
sorted_rows.compact.sort.each do |row|
|
54
|
+
out.puts unstring(rows[row.last])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
data/lib/sycsvpro/version.rb
CHANGED
data/lib/sycsvpro.rb
CHANGED
@@ -11,7 +11,7 @@ module Sycsvpro
|
|
11
11
|
|
12
12
|
it "should allocate one value to a key" do
|
13
13
|
key = "1"
|
14
|
-
rows = "1-
|
14
|
+
rows = "1-7"
|
15
15
|
cols = "0"
|
16
16
|
allocator = Allocator.new(infile: @in_file, outfile: @out_file,
|
17
17
|
key: key, rows: rows, cols: cols)
|
@@ -32,7 +32,7 @@ module Sycsvpro
|
|
32
32
|
|
33
33
|
it "should allocate multiple values to a key" do
|
34
34
|
key = "0"
|
35
|
-
rows = "1-
|
35
|
+
rows = "1-7"
|
36
36
|
cols = "4-5"
|
37
37
|
allocator = Allocator.new(infile: @in_file, outfile: @out_file,
|
38
38
|
key: key, rows: rows, cols: cols)
|
@@ -0,0 +1 @@
|
|
1
|
+
For testing listing insert files with ScriptList
|