csv_decision 0.2.0 → 0.3.0

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.
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
@@ -177,6 +177,64 @@ which eventually get evaluated and removed.</p>
177
177
  <p>Returns true if this is a multi-row result.</p>
178
178
  </div></span>
179
179
 
180
+ </li>
181
+
182
+
183
+ <li class="public ">
184
+ <span class="summary_signature">
185
+
186
+ <a href="#outs-instance_method" title="#outs (instance method)">#<strong>outs</strong> &#x21d2; Hash{Index=&gt;Dictionary::Entry} </a>
187
+
188
+
189
+
190
+ </span>
191
+
192
+
193
+
194
+
195
+ <span class="note title readonly">readonly</span>
196
+
197
+
198
+
199
+
200
+
201
+
202
+ <span class="private note title">private</span>
203
+
204
+
205
+ <span class="summary_desc"><div class='inline'>
206
+ <p>Output columns.</p>
207
+ </div></span>
208
+
209
+ </li>
210
+
211
+
212
+ <li class="public ">
213
+ <span class="summary_signature">
214
+
215
+ <a href="#outs_functions-instance_method" title="#outs_functions (instance method)">#<strong>outs_functions</strong> &#x21d2; nil, true </a>
216
+
217
+
218
+
219
+ </span>
220
+
221
+
222
+
223
+
224
+ <span class="note title readonly">readonly</span>
225
+
226
+
227
+
228
+
229
+
230
+
231
+ <span class="private note title">private</span>
232
+
233
+
234
+ <span class="summary_desc"><div class='inline'>
235
+ <p>Set to true if the table has output functions.</p>
236
+ </div></span>
237
+
180
238
  </li>
181
239
 
182
240
 
@@ -405,12 +463,6 @@ result, along with the partial result required to evaluate functions.</p>
405
463
  <pre class="lines">
406
464
 
407
465
 
408
- 19
409
- 20
410
- 21
411
- 22
412
- 23
413
- 24
414
466
  25
415
467
  26
416
468
  27
@@ -422,13 +474,17 @@ result, along with the partial result required to evaluate functions.</p>
422
474
  33
423
475
  34
424
476
  35
425
- 36</pre>
477
+ 36
478
+ 37
479
+ 38
480
+ 39</pre>
426
481
  </td>
427
482
  <td>
428
- <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 19</span>
483
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 25</span>
429
484
 
430
485
  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>table:</span><span class='comma'>,</span> <span class='label'>input:</span><span class='rparen'>)</span>
431
486
  <span class='ivar'>@outs</span> <span class='op'>=</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_columns'>columns</span><span class='period'>.</span><span class='id identifier rubyid_outs'>outs</span>
487
+ <span class='ivar'>@outs_functions</span> <span class='op'>=</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_outs_functions'>outs_functions</span>
432
488
  <span class='ivar'>@if_columns</span> <span class='op'>=</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_columns'>columns</span><span class='period'>.</span><span class='id identifier rubyid_ifs'>ifs</span>
433
489
 
434
490
  <span class='comment'># Partial result always copies in the input hash for calculating output functions.
@@ -436,14 +492,10 @@ result, along with the partial result required to evaluate functions.</p>
436
492
  </span> <span class='comment'># have the same symbol as an input hash key.
437
493
  </span> <span class='comment'># However, the rest of this hash is mutated as output column evaluation results
438
494
  </span> <span class='comment'># are accumulated.
439
- </span> <span class='ivar'>@partial_result</span> <span class='op'>=</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:hash</span><span class='rbracket'>]</span><span class='op'>&amp;.</span><span class='id identifier rubyid_slice'>slice</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_columns'>columns</span><span class='period'>.</span><span class='id identifier rubyid_input_keys'>input_keys</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_outs_functions'>outs_functions</span>
495
+ </span> <span class='ivar'>@partial_result</span> <span class='op'>=</span> <span class='id identifier rubyid_input'>input</span><span class='op'>&amp;.</span><span class='id identifier rubyid_slice'>slice</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_columns'>columns</span><span class='period'>.</span><span class='id identifier rubyid_input_keys'>input_keys</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@outs_functions</span>
440
496
 
441
497
  <span class='comment'># Attributes hash contains the output decision key value pairs
442
498
  </span> <span class='ivar'>@attributes</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
443
-
444
- <span class='comment'># Set to true if the result has more than one row.
445
- </span> <span class='comment'># Only possible for the first_match: false option.
446
- </span> <span class='ivar'>@multi_result</span> <span class='op'>=</span> <span class='kw'>false</span>
447
499
  <span class='kw'>end</span></pre>
448
500
  </td>
449
501
  </tr>
@@ -572,6 +624,71 @@ which eventually get evaluated and removed.</p>
572
624
  <pre class="lines">
573
625
 
574
626
 
627
+ 22
628
+ 23
629
+ 24</pre>
630
+ </td>
631
+ <td>
632
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 22</span>
633
+
634
+ <span class='kw'>def</span> <span class='id identifier rubyid_multi_result'>multi_result</span>
635
+ <span class='ivar'>@multi_result</span>
636
+ <span class='kw'>end</span></pre>
637
+ </td>
638
+ </tr>
639
+ </table>
640
+ </div>
641
+
642
+
643
+ <span id=""></span>
644
+ <div class="method_details ">
645
+ <h3 class="signature " id="outs-instance_method">
646
+
647
+ #<strong>outs</strong> &#x21d2; <tt>Hash{<span class='object_link'><a href="Index.html" title="CSVDecision::Index (class)">Index</a></span>=&gt;<span class='object_link'><a href="Dictionary/Entry.html" title="CSVDecision::Dictionary::Entry (class)">Dictionary::Entry</a></span>}</tt> <span class="extras">(readonly)</span>
648
+
649
+
650
+
651
+
652
+
653
+ </h3><div class="docstring">
654
+ <div class="discussion">
655
+ <p class="note private">
656
+ <strong>This method is part of a private API.</strong>
657
+ You should avoid using this method if possible, as it may be removed or be changed in the future.
658
+ </p>
659
+
660
+ <p>Returns Output columns.</p>
661
+
662
+
663
+ </div>
664
+ </div>
665
+ <div class="tags">
666
+
667
+ <p class="tag_title">Returns:</p>
668
+ <ul class="return">
669
+
670
+ <li>
671
+
672
+
673
+ <span class='type'>(<tt>Hash{<span class='object_link'><a href="Index.html" title="CSVDecision::Index (class)">Index</a></span>=&gt;<span class='object_link'><a href="Dictionary/Entry.html" title="CSVDecision::Dictionary::Entry (class)">Dictionary::Entry</a></span>}</tt>)</span>
674
+
675
+
676
+
677
+ &mdash;
678
+ <div class='inline'>
679
+ <p>Output columns.</p>
680
+ </div>
681
+
682
+ </li>
683
+
684
+ </ul>
685
+
686
+ </div><table class="source_code">
687
+ <tr>
688
+ <td>
689
+ <pre class="lines">
690
+
691
+
575
692
  16
576
693
  17
577
694
  18</pre>
@@ -579,8 +696,73 @@ which eventually get evaluated and removed.</p>
579
696
  <td>
580
697
  <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 16</span>
581
698
 
582
- <span class='kw'>def</span> <span class='id identifier rubyid_multi_result'>multi_result</span>
583
- <span class='ivar'>@multi_result</span>
699
+ <span class='kw'>def</span> <span class='id identifier rubyid_outs'>outs</span>
700
+ <span class='ivar'>@outs</span>
701
+ <span class='kw'>end</span></pre>
702
+ </td>
703
+ </tr>
704
+ </table>
705
+ </div>
706
+
707
+
708
+ <span id=""></span>
709
+ <div class="method_details ">
710
+ <h3 class="signature " id="outs_functions-instance_method">
711
+
712
+ #<strong>outs_functions</strong> &#x21d2; <tt>nil</tt>, <tt>true</tt> <span class="extras">(readonly)</span>
713
+
714
+
715
+
716
+
717
+
718
+ </h3><div class="docstring">
719
+ <div class="discussion">
720
+ <p class="note private">
721
+ <strong>This method is part of a private API.</strong>
722
+ You should avoid using this method if possible, as it may be removed or be changed in the future.
723
+ </p>
724
+
725
+ <p>Returns Set to true if the table has output functions.</p>
726
+
727
+
728
+ </div>
729
+ </div>
730
+ <div class="tags">
731
+
732
+ <p class="tag_title">Returns:</p>
733
+ <ul class="return">
734
+
735
+ <li>
736
+
737
+
738
+ <span class='type'>(<tt>nil</tt>, <tt>true</tt>)</span>
739
+
740
+
741
+
742
+ &mdash;
743
+ <div class='inline'>
744
+ <p>Set to true if the table has output functions.</p>
745
+ </div>
746
+
747
+ </li>
748
+
749
+ </ul>
750
+
751
+ </div><table class="source_code">
752
+ <tr>
753
+ <td>
754
+ <pre class="lines">
755
+
756
+
757
+ 19
758
+ 20
759
+ 21</pre>
760
+ </td>
761
+ <td>
762
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 19</span>
763
+
764
+ <span class='kw'>def</span> <span class='id identifier rubyid_outs_functions'>outs_functions</span>
765
+ <span class='ivar'>@outs_functions</span>
584
766
  <span class='kw'>end</span></pre>
585
767
  </td>
586
768
  </tr>
@@ -639,12 +821,12 @@ which eventually get evaluated and removed.</p>
639
821
  <pre class="lines">
640
822
 
641
823
 
642
- 49
643
- 50
644
- 51</pre>
824
+ 52
825
+ 53
826
+ 54</pre>
645
827
  </td>
646
828
  <td>
647
- <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 49</span>
829
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 52</span>
648
830
 
649
831
  <span class='kw'>def</span> <span class='id identifier rubyid_accumulate_outs'>accumulate_outs</span><span class='lparen'>(</span><span class='id identifier rubyid_row'>row</span><span class='rparen'>)</span>
650
832
  <span class='ivar'>@outs</span><span class='period'>.</span><span class='id identifier rubyid_each_pair'>each_pair</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_col'>col</span><span class='comma'>,</span> <span class='id identifier rubyid_column'>column</span><span class='op'>|</span> <span class='id identifier rubyid_add_cell'>add_cell</span><span class='lparen'>(</span><span class='label'>column_name:</span> <span class='id identifier rubyid_column'>column</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='label'>cell:</span> <span class='id identifier rubyid_row'>row</span><span class='lbracket'>[</span><span class='id identifier rubyid_col'>col</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
@@ -700,12 +882,12 @@ values to the final result hash.</p>
700
882
  <pre class="lines">
701
883
 
702
884
 
703
- 42
704
- 43
705
- 44</pre>
885
+ 45
886
+ 46
887
+ 47</pre>
706
888
  </td>
707
889
  <td>
708
- <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 42</span>
890
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 45</span>
709
891
 
710
892
  <span class='kw'>def</span> <span class='id identifier rubyid_add_outs'>add_outs</span><span class='lparen'>(</span><span class='id identifier rubyid_row'>row</span><span class='rparen'>)</span>
711
893
  <span class='ivar'>@outs</span><span class='period'>.</span><span class='id identifier rubyid_each_pair'>each_pair</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_col'>col</span><span class='comma'>,</span> <span class='id identifier rubyid_column'>column</span><span class='op'>|</span> <span class='ivar'>@attributes</span><span class='lbracket'>[</span><span class='id identifier rubyid_column'>column</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_row'>row</span><span class='lbracket'>[</span><span class='id identifier rubyid_col'>col</span><span class='rbracket'>]</span> <span class='rbrace'>}</span>
@@ -782,12 +964,12 @@ values to the final result hash.</p>
782
964
  <pre class="lines">
783
965
 
784
966
 
785
- 82
786
- 83
787
- 84</pre>
967
+ 85
968
+ 86
969
+ 87</pre>
788
970
  </td>
789
971
  <td>
790
- <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 82</span>
972
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 85</span>
791
973
 
792
974
  <span class='kw'>def</span> <span class='id identifier rubyid_eval_cell_proc'>eval_cell_proc</span><span class='lparen'>(</span><span class='label'>proc:</span><span class='comma'>,</span> <span class='label'>column_name:</span><span class='comma'>,</span> <span class='label'>index:</span><span class='rparen'>)</span>
793
975
  <span class='ivar'>@attributes</span><span class='lbracket'>[</span><span class='id identifier rubyid_column_name'>column_name</span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='id identifier rubyid_index'>index</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_proc'>proc</span><span class='period'>.</span><span class='id identifier rubyid_function'>function</span><span class='lbracket'>[</span><span class='id identifier rubyid_partial_result'>partial_result</span><span class='lparen'>(</span><span class='id identifier rubyid_index'>index</span><span class='rparen'>)</span><span class='rbracket'>]</span>
@@ -856,18 +1038,18 @@ result, along with the partial result required to evaluate functions.</p>
856
1038
  <pre class="lines">
857
1039
 
858
1040
 
859
- 67
860
- 68
861
- 69
862
1041
  70
863
1042
  71
864
1043
  72
865
1044
  73
866
1045
  74
867
- 75</pre>
1046
+ 75
1047
+ 76
1048
+ 77
1049
+ 78</pre>
868
1050
  </td>
869
1051
  <td>
870
- <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 67</span>
1052
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 70</span>
871
1053
 
872
1054
  <span class='kw'>def</span> <span class='id identifier rubyid_eval_outs'>eval_outs</span><span class='lparen'>(</span><span class='id identifier rubyid_row'>row</span><span class='rparen'>)</span>
873
1055
  <span class='comment'># Set the constants first, in case the functions refer to them
@@ -926,15 +1108,15 @@ result, along with the partial result required to evaluate functions.</p>
926
1108
  <pre class="lines">
927
1109
 
928
1110
 
929
- 55
930
- 56
931
- 57
932
1111
  58
933
1112
  59
934
- 60</pre>
1113
+ 60
1114
+ 61
1115
+ 62
1116
+ 63</pre>
935
1117
  </td>
936
1118
  <td>
937
- <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 55</span>
1119
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 58</span>
938
1120
 
939
1121
  <span class='kw'>def</span> <span class='id identifier rubyid_final'>final</span>
940
1122
  <span class='comment'># If there are no if: columns, then nothing needs to be filtered out of this result hash.
@@ -952,7 +1134,7 @@ result, along with the partial result required to evaluate functions.</p>
952
1134
  </div>
953
1135
 
954
1136
  <div id="footer">
955
- Generated on Sat Jan 13 10:02:46 2018 by
1137
+ Generated on Sat Jan 20 15:44:35 2018 by
956
1138
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
957
1139
  0.9.12 (ruby-2.4.0).
958
1140
  </div>