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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/README.md +11 -8
  4. data/benchmarks/rufus_decision.rb +9 -1
  5. data/csv_decision.gemspec +1 -1
  6. data/doc/CSVDecision/CellValidationError.html +1 -1
  7. data/doc/CSVDecision/Columns/Dictionary.html +29 -29
  8. data/doc/CSVDecision/Columns.html +394 -47
  9. data/doc/CSVDecision/Data.html +2 -2
  10. data/doc/CSVDecision/Decide.html +23 -159
  11. data/doc/CSVDecision/Decision.html +370 -32
  12. data/doc/CSVDecision/Defaults.html +1 -1
  13. data/doc/CSVDecision/Dictionary/Entry.html +157 -55
  14. data/doc/CSVDecision/Dictionary.html +37 -21
  15. data/doc/CSVDecision/Error.html +1 -1
  16. data/doc/CSVDecision/FileError.html +1 -1
  17. data/doc/CSVDecision/Header.html +142 -1
  18. data/doc/CSVDecision/Index.html +741 -0
  19. data/doc/CSVDecision/Input.html +14 -61
  20. data/doc/CSVDecision/Load.html +1 -1
  21. data/doc/CSVDecision/Matchers/Constant.html +1 -1
  22. data/doc/CSVDecision/Matchers/Function.html +1 -1
  23. data/doc/CSVDecision/Matchers/Guard.html +13 -147
  24. data/doc/CSVDecision/Matchers/Matcher.html +13 -13
  25. data/doc/CSVDecision/Matchers/Numeric.html +1 -1
  26. data/doc/CSVDecision/Matchers/Pattern.html +1 -1
  27. data/doc/CSVDecision/Matchers/Proc.html +147 -14
  28. data/doc/CSVDecision/Matchers/Range.html +1 -1
  29. data/doc/CSVDecision/Matchers/Symbol.html +1 -1
  30. data/doc/CSVDecision/Matchers.html +55 -162
  31. data/doc/CSVDecision/Options.html +21 -21
  32. data/doc/CSVDecision/Parse.html +2 -180
  33. data/doc/CSVDecision/Result.html +220 -38
  34. data/doc/CSVDecision/ScanRow.html +69 -325
  35. data/doc/CSVDecision/Table.html +128 -40
  36. data/doc/CSVDecision/TableValidationError.html +1 -1
  37. data/doc/CSVDecision/Validate.html +1 -1
  38. data/doc/CSVDecision.html +4 -4
  39. data/doc/_index.html +8 -8
  40. data/doc/class_list.html +1 -1
  41. data/doc/file.README.html +13 -11
  42. data/doc/index.html +13 -11
  43. data/doc/method_list.html +206 -150
  44. data/doc/top-level-namespace.html +1 -1
  45. data/lib/csv_decision/columns.rb +87 -1
  46. data/lib/csv_decision/decision.rb +54 -29
  47. data/lib/csv_decision/defaults.rb +1 -1
  48. data/lib/csv_decision/dictionary.rb +32 -22
  49. data/lib/csv_decision/header.rb +17 -0
  50. data/lib/csv_decision/index.rb +107 -0
  51. data/lib/csv_decision/input.rb +45 -13
  52. data/lib/csv_decision/matchers/guard.rb +2 -0
  53. data/lib/csv_decision/matchers.rb +14 -8
  54. data/lib/csv_decision/options.rb +7 -19
  55. data/lib/csv_decision/parse.rb +12 -96
  56. data/lib/csv_decision/result.rb +10 -9
  57. data/lib/csv_decision/scan_row.rb +20 -44
  58. data/lib/csv_decision/table.rb +7 -4
  59. data/lib/csv_decision.rb +1 -1
  60. data/spec/csv_decision/columns_spec.rb +6 -6
  61. data/spec/csv_decision/data_spec.rb +0 -5
  62. data/spec/csv_decision/index_spec.rb +58 -0
  63. data/spec/csv_decision/input_spec.rb +7 -2
  64. data/spec/csv_decision/options_spec.rb +16 -1
  65. data/spec/csv_decision/parse_spec.rb +4 -5
  66. data/spec/csv_decision/table_spec.rb +70 -0
  67. data/spec/data/{valid → invalid}/empty.csv +0 -0
  68. data/spec/data/valid/index_example.csv +12 -0
  69. data/spec/data/valid/multi_column_index.csv +10 -0
  70. data/spec/data/valid/multi_column_index2.csv +12 -0
  71. data/spec/data/valid/options_in_file3.csv +13 -0
  72. metadata +16 -5
  73. data/lib/csv_decision/decide.rb +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67d87d1568c8a9427eca158d72473cceab9ea0cc
4
- data.tar.gz: acaf91742be83cdee27cad0135feed854bff8f4d
3
+ metadata.gz: 91948b110f220bb5a54cc74494d51b189bf5af51
4
+ data.tar.gz: 23cd2d5e7aa16a301f09186ccc00b57260d3b275
5
5
  SHA512:
6
- metadata.gz: 983a199ab2f592b3b78fb6cef1b95e0af0a45aaaca9f352d7ff22a7e7b5ade08268d6efb41530a137fbd00c77516e9d12f3d21e66c6901ea927611600c1d2c7a
7
- data.tar.gz: a75924ebd838c43be4c876e52332bccb1b57be3ecd719c9a81283bc449a14174294f90df64e08db2f50df463920f42ffeec5a8ec148106c589332336d0bfee34
6
+ metadata.gz: '0149f4aa493e08f157e859a79ab09a03f3a980523d1affe16ad1179c6a2ee58e94906daefc1e5bf0456b8d507c8e2fb82e710939ac8ca84648beabb564b045b0'
7
+ data.tar.gz: 8adce55f750392d0478b0e985ff6a400d4a755e8385684ce29f586220669aa3ddc1ce9fb85efe3a9b108282a89e92a83e2eb4036e9736b1f0b2ed73461f6aa61
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- ## v0.2.0, January 2018.
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', '~> 0.1'
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
- * Text-only input columns may be indexed for faster lookup performance.
286
- * Input hash values may be (conditionally) defaulted with a constant or a function call.
287
- * Output columns may construct interpolated strings referencing column symbols.
288
- * Supply a pre-defined library of functions that can be called within input columns to
289
- implement matching logic or from the output columns to formulate the final decision.
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 tailored logic.
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 (no index)',
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.2.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 13 10:02:46 2018 by
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
- 35
339
- 36
340
- 37
341
- 38
342
- 39
343
- 40
344
- 41</pre>
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 35</span>
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
- 19
417
- 20
418
- 21</pre>
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 19</span>
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
- 26
484
- 27
485
- 28</pre>
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 26</span>
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
- 33
550
- 34
551
- 35</pre>
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 33</span>
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
- 22
615
- 23
616
- 24</pre>
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 22</span>
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
- 29
680
- 30
681
- 31</pre>
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 29</span>
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 13 10:02:47 2018 by
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>