csv_decision 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +11 -8
- data/benchmarks/rufus_decision.rb +9 -1
- data/csv_decision.gemspec +1 -1
- data/doc/CSVDecision/CellValidationError.html +1 -1
- data/doc/CSVDecision/Columns/Dictionary.html +29 -29
- data/doc/CSVDecision/Columns.html +394 -47
- data/doc/CSVDecision/Data.html +2 -2
- data/doc/CSVDecision/Decide.html +23 -159
- data/doc/CSVDecision/Decision.html +370 -32
- data/doc/CSVDecision/Defaults.html +1 -1
- data/doc/CSVDecision/Dictionary/Entry.html +157 -55
- data/doc/CSVDecision/Dictionary.html +37 -21
- data/doc/CSVDecision/Error.html +1 -1
- data/doc/CSVDecision/FileError.html +1 -1
- data/doc/CSVDecision/Header.html +142 -1
- data/doc/CSVDecision/Index.html +741 -0
- data/doc/CSVDecision/Input.html +14 -61
- data/doc/CSVDecision/Load.html +1 -1
- data/doc/CSVDecision/Matchers/Constant.html +1 -1
- data/doc/CSVDecision/Matchers/Function.html +1 -1
- data/doc/CSVDecision/Matchers/Guard.html +13 -147
- data/doc/CSVDecision/Matchers/Matcher.html +13 -13
- data/doc/CSVDecision/Matchers/Numeric.html +1 -1
- data/doc/CSVDecision/Matchers/Pattern.html +1 -1
- data/doc/CSVDecision/Matchers/Proc.html +147 -14
- data/doc/CSVDecision/Matchers/Range.html +1 -1
- data/doc/CSVDecision/Matchers/Symbol.html +1 -1
- data/doc/CSVDecision/Matchers.html +55 -162
- data/doc/CSVDecision/Options.html +21 -21
- data/doc/CSVDecision/Parse.html +2 -180
- data/doc/CSVDecision/Result.html +220 -38
- data/doc/CSVDecision/ScanRow.html +69 -325
- data/doc/CSVDecision/Table.html +128 -40
- data/doc/CSVDecision/TableValidationError.html +1 -1
- data/doc/CSVDecision/Validate.html +1 -1
- data/doc/CSVDecision.html +4 -4
- data/doc/_index.html +8 -8
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +13 -11
- data/doc/index.html +13 -11
- data/doc/method_list.html +206 -150
- data/doc/top-level-namespace.html +1 -1
- data/lib/csv_decision/columns.rb +87 -1
- data/lib/csv_decision/decision.rb +54 -29
- data/lib/csv_decision/defaults.rb +1 -1
- data/lib/csv_decision/dictionary.rb +32 -22
- data/lib/csv_decision/header.rb +17 -0
- data/lib/csv_decision/index.rb +107 -0
- data/lib/csv_decision/input.rb +45 -13
- data/lib/csv_decision/matchers/guard.rb +2 -0
- data/lib/csv_decision/matchers.rb +14 -8
- data/lib/csv_decision/options.rb +7 -19
- data/lib/csv_decision/parse.rb +12 -96
- data/lib/csv_decision/result.rb +10 -9
- data/lib/csv_decision/scan_row.rb +20 -44
- data/lib/csv_decision/table.rb +7 -4
- data/lib/csv_decision.rb +1 -1
- data/spec/csv_decision/columns_spec.rb +6 -6
- data/spec/csv_decision/data_spec.rb +0 -5
- data/spec/csv_decision/index_spec.rb +58 -0
- data/spec/csv_decision/input_spec.rb +7 -2
- data/spec/csv_decision/options_spec.rb +16 -1
- data/spec/csv_decision/parse_spec.rb +4 -5
- data/spec/csv_decision/table_spec.rb +70 -0
- data/spec/data/{valid → invalid}/empty.csv +0 -0
- data/spec/data/valid/index_example.csv +12 -0
- data/spec/data/valid/multi_column_index.csv +10 -0
- data/spec/data/valid/multi_column_index2.csv +12 -0
- data/spec/data/valid/options_in_file3.csv +13 -0
- metadata +16 -5
- data/lib/csv_decision/decide.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91948b110f220bb5a54cc74494d51b189bf5af51
|
4
|
+
data.tar.gz: 23cd2d5e7aa16a301f09186ccc00b57260d3b275
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0149f4aa493e08f157e859a79ab09a03f3a980523d1affe16ad1179c6a2ee58e94906daefc1e5bf0456b8d507c8e2fb82e710939ac8ca84648beabb564b045b0'
|
7
|
+
data.tar.gz: 8adce55f750392d0478b0e985ff6a400d4a755e8385684ce29f586220669aa3ddc1ce9fb85efe3a9b108282a89e92a83e2eb4036e9736b1f0b2ed73461f6aa61
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
## v0.
|
1
|
+
## v0.3.0, 20 January 2018.
|
2
|
+
*Additions*
|
3
|
+
- Index one or more text-only input columns for faster lookup performance.
|
4
|
+
|
5
|
+
## v0.2.0, 13 January 2018.
|
2
6
|
*Additions*
|
3
7
|
- Set values in the input hash either as a default or unconditionally.
|
4
8
|
|
data/README.md
CHANGED
@@ -36,7 +36,7 @@ see `benchmarks/rufus_decision.rb`.)
|
|
36
36
|
To get started, just add `csv_decision` to your `Gemfile`, and then run `bundle`:
|
37
37
|
|
38
38
|
```ruby
|
39
|
-
gem 'csv_decision'
|
39
|
+
gem 'csv_decision'
|
40
40
|
```
|
41
41
|
|
42
42
|
or simply
|
@@ -126,7 +126,8 @@ Complete documentation of all table parameters is in the code - see
|
|
126
126
|
### CSV Decision features
|
127
127
|
* Either returns the first matching row as a hash (default), or accumulates all matches as an
|
128
128
|
array of hashes (i.e., `parse` option `first_match: false` or CSV file option `accumulate`).
|
129
|
-
* Fast decision-time performance (see `benchmarks` folder).
|
129
|
+
* Fast decision-time performance (see `benchmarks` folder). Automatically indexes all
|
130
|
+
text-only columns that do not contain any empty strings.
|
130
131
|
* In addition to simple strings, `csv_decision` can match basic Ruby constants (e.g., `=nil`),
|
131
132
|
regular expressions (e.g., `=~ on|off`), comparisons (e.g., `> 100.0` ) and
|
132
133
|
Ruby-style ranges (e.g., `1..10`)
|
@@ -282,13 +283,15 @@ table.decide(ISIN: '123456789012', country: 'GB', class: 'private') #=> {PAID: '
|
|
282
283
|
### Planned features
|
283
284
|
`csv_decision` is still a work in progress, and will be enhanced to support
|
284
285
|
the following features:
|
285
|
-
*
|
286
|
-
|
287
|
-
|
288
|
-
*
|
289
|
-
|
286
|
+
* Supply a pre-defined library of functions that may be called within input columns to
|
287
|
+
implement custom matching logic, or from the output columns to formulate the final
|
288
|
+
decision.
|
289
|
+
* Built-in lookup functions evaluate other decision tables to implement guard conditions,
|
290
|
+
or supply output values.
|
290
291
|
* Available functions may be extended with a user-supplied library of Ruby methods
|
291
|
-
for
|
292
|
+
for custom logic.
|
293
|
+
* Output columns may construct interpolated strings containing references to column
|
294
|
+
symbols.
|
292
295
|
|
293
296
|
### Reasons for the limitations of column expressions
|
294
297
|
The simple column expressions allowed by `csv_decision` are purposely limited for reasons of
|
@@ -13,7 +13,15 @@ RUFUS_OPTIONS = { open_uri: false, ruby_eval: false }.freeze
|
|
13
13
|
|
14
14
|
benchmarks = [
|
15
15
|
{
|
16
|
-
name: 'String compares only
|
16
|
+
name: 'String compares only with index',
|
17
|
+
data: 'index_example.csv',
|
18
|
+
input: { 'topic' => 'politics', 'region' => 'Arctic' },
|
19
|
+
# Expected results for first_match and accumulate
|
20
|
+
first_match: { 'team_member' => 'Henry' },
|
21
|
+
accumulate: { 'team_member' => ['Henry', 'Zach'] }
|
22
|
+
},
|
23
|
+
{
|
24
|
+
name: 'String compares only',
|
17
25
|
data: 'simple_example.csv',
|
18
26
|
input: { 'topic' => 'culture', 'region' => 'America' },
|
19
27
|
# Expected results for first_match and accumulate
|
data/csv_decision.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'csv_decision'
|
8
|
-
spec.version = '0.
|
8
|
+
spec.version = '0.3.0'
|
9
9
|
spec.authors = ['Brett Vickers']
|
10
10
|
spec.email = ['brett@phillips-vickers.com']
|
11
11
|
spec.description = 'CSV based Ruby decision tables.'
|
@@ -133,7 +133,7 @@
|
|
133
133
|
</div>
|
134
134
|
|
135
135
|
<div id="footer">
|
136
|
-
Generated on Sat Jan
|
136
|
+
Generated on Sat Jan 20 15:44:35 2018 by
|
137
137
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
138
138
|
0.9.12 (ruby-2.4.0).
|
139
139
|
</div>
|
@@ -335,16 +335,16 @@ overlap with input column symbols.</p>
|
|
335
335
|
<pre class="lines">
|
336
336
|
|
337
337
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
338
|
+
118
|
339
|
+
119
|
340
|
+
120
|
341
|
+
121
|
342
|
+
122
|
343
|
+
123
|
344
|
+
124</pre>
|
345
345
|
</td>
|
346
346
|
<td>
|
347
|
-
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line
|
347
|
+
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line 118</span>
|
348
348
|
|
349
349
|
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
|
350
350
|
<span class='ivar'>@columns</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
@@ -413,12 +413,12 @@ overlap with input column symbols.</p>
|
|
413
413
|
<pre class="lines">
|
414
414
|
|
415
415
|
|
416
|
-
|
417
|
-
|
418
|
-
|
416
|
+
102
|
417
|
+
103
|
418
|
+
104</pre>
|
419
419
|
</td>
|
420
420
|
<td>
|
421
|
-
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line
|
421
|
+
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line 102</span>
|
422
422
|
|
423
423
|
<span class='kw'>def</span> <span class='id identifier rubyid_columns'>columns</span>
|
424
424
|
<span class='ivar'>@columns</span>
|
@@ -480,12 +480,12 @@ subset of :ins.</p>
|
|
480
480
|
<pre class="lines">
|
481
481
|
|
482
482
|
|
483
|
-
|
484
|
-
|
485
|
-
|
483
|
+
109
|
484
|
+
110
|
485
|
+
111</pre>
|
486
486
|
</td>
|
487
487
|
<td>
|
488
|
-
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line
|
488
|
+
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line 109</span>
|
489
489
|
|
490
490
|
<span class='kw'>def</span> <span class='id identifier rubyid_defaults'>defaults</span>
|
491
491
|
<span class='ivar'>@defaults</span>
|
@@ -546,12 +546,12 @@ of :outs.</p>
|
|
546
546
|
<pre class="lines">
|
547
547
|
|
548
548
|
|
549
|
-
|
550
|
-
|
551
|
-
|
549
|
+
116
|
550
|
+
117
|
551
|
+
118</pre>
|
552
552
|
</td>
|
553
553
|
<td>
|
554
|
-
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line
|
554
|
+
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line 116</span>
|
555
555
|
|
556
556
|
<span class='kw'>def</span> <span class='id identifier rubyid_ifs'>ifs</span>
|
557
557
|
<span class='ivar'>@ifs</span>
|
@@ -611,12 +611,12 @@ of :outs.</p>
|
|
611
611
|
<pre class="lines">
|
612
612
|
|
613
613
|
|
614
|
-
|
615
|
-
|
616
|
-
|
614
|
+
105
|
615
|
+
106
|
616
|
+
107</pre>
|
617
617
|
</td>
|
618
618
|
<td>
|
619
|
-
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line
|
619
|
+
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line 105</span>
|
620
620
|
|
621
621
|
<span class='kw'>def</span> <span class='id identifier rubyid_ins'>ins</span>
|
622
622
|
<span class='ivar'>@ins</span>
|
@@ -676,12 +676,12 @@ of :outs.</p>
|
|
676
676
|
<pre class="lines">
|
677
677
|
|
678
678
|
|
679
|
-
|
680
|
-
|
681
|
-
|
679
|
+
112
|
680
|
+
113
|
681
|
+
114</pre>
|
682
682
|
</td>
|
683
683
|
<td>
|
684
|
-
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line
|
684
|
+
<pre class="code"><span class="info file"># File 'lib/csv_decision/columns.rb', line 112</span>
|
685
685
|
|
686
686
|
<span class='kw'>def</span> <span class='id identifier rubyid_outs'>outs</span>
|
687
687
|
<span class='ivar'>@outs</span>
|
@@ -697,7 +697,7 @@ of :outs.</p>
|
|
697
697
|
</div>
|
698
698
|
|
699
699
|
<div id="footer">
|
700
|
-
Generated on Sat Jan
|
700
|
+
Generated on Sat Jan 20 15:44:35 2018 by
|
701
701
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
702
702
|
0.9.12 (ruby-2.4.0).
|
703
703
|
</div>
|