csv_decision 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/benchmarks/rufus_decision.rb +1 -1
  4. data/csv_decision.gemspec +1 -1
  5. data/doc/CSVDecision.html +1 -1
  6. data/doc/CSVDecision/CellValidationError.html +1 -1
  7. data/doc/CSVDecision/Columns.html +1 -1
  8. data/doc/CSVDecision/Columns/Dictionary.html +1 -1
  9. data/doc/CSVDecision/Data.html +1 -1
  10. data/doc/CSVDecision/Decision.html +42 -34
  11. data/doc/CSVDecision/Defaults.html +1 -1
  12. data/doc/CSVDecision/Dictionary.html +1 -1
  13. data/doc/CSVDecision/Dictionary/Entry.html +1 -1
  14. data/doc/CSVDecision/Error.html +1 -1
  15. data/doc/CSVDecision/FileError.html +1 -1
  16. data/doc/CSVDecision/Header.html +1 -1
  17. data/doc/CSVDecision/Index.html +1 -1
  18. data/doc/CSVDecision/Input.html +65 -47
  19. data/doc/CSVDecision/Load.html +1 -1
  20. data/doc/CSVDecision/Matchers.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 +1 -1
  24. data/doc/CSVDecision/Matchers/Matcher.html +1 -1
  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 +1 -1
  28. data/doc/CSVDecision/Matchers/Range.html +1 -1
  29. data/doc/CSVDecision/Matchers/Symbol.html +1 -1
  30. data/doc/CSVDecision/Options.html +1 -1
  31. data/doc/CSVDecision/Parse.html +1 -1
  32. data/doc/CSVDecision/Result.html +5 -5
  33. data/doc/CSVDecision/ScanRow.html +1 -1
  34. data/doc/CSVDecision/Table.html +2 -12
  35. data/doc/CSVDecision/TableValidationError.html +1 -1
  36. data/doc/CSVDecision/Validate.html +1 -1
  37. data/doc/_index.html +1 -1
  38. data/doc/file.README.html +1 -1
  39. data/doc/index.html +1 -1
  40. data/doc/top-level-namespace.html +1 -1
  41. data/lib/csv_decision/decision.rb +56 -33
  42. data/lib/csv_decision/input.rb +4 -27
  43. data/lib/csv_decision/result.rb +5 -5
  44. data/lib/csv_decision/table.rb +0 -5
  45. data/spec/csv_decision/input_spec.rb +0 -2
  46. data/spec/csv_decision/table_spec.rb +3 -0
  47. data/spec/data/valid/index_example.csv +11 -11
  48. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91948b110f220bb5a54cc74494d51b189bf5af51
4
- data.tar.gz: 23cd2d5e7aa16a301f09186ccc00b57260d3b275
3
+ metadata.gz: 40af539bd889c1b4bba0b9cced1c517121dd331d
4
+ data.tar.gz: 60e3f727ad24252bd78ccfc3f6b69be77d2c7b4b
5
5
  SHA512:
6
- metadata.gz: '0149f4aa493e08f157e859a79ab09a03f3a980523d1affe16ad1179c6a2ee58e94906daefc1e5bf0456b8d507c8e2fb82e710939ac8ca84648beabb564b045b0'
7
- data.tar.gz: 8adce55f750392d0478b0e985ff6a400d4a755e8385684ce29f586220669aa3ddc1ce9fb85efe3a9b108282a89e92a83e2eb4036e9736b1f0b2ed73461f6aa61
6
+ metadata.gz: 22aae99d06ad663ebc6bed44d19c54a3e55b059f58e8dab1a9b1cb72114a104297d8513911afde5cec738dd3237034e8a55e8097f85e67991d79d647b78ea434
7
+ data.tar.gz: e869bc5eaccbe556cd9e76b3ef5c0bc3d10daa2cc7f47ec4e8ec2151d0c8c4dbf2166dc4eed34357875ca2335aca3fe74957e1a16f6ff1ddefc474baf50505c8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.3.1, 21 January 2018.
2
+ *changes*
3
+ - Optimize code.
4
+
1
5
  ## v0.3.0, 20 January 2018.
2
6
  *Additions*
3
7
  - Index one or more text-only input columns for faster lookup performance.
@@ -87,7 +87,7 @@ puts ""
87
87
 
88
88
  GC.start
89
89
  x.report("Rufus decision (first_match: #{first_match}) - #{name}: ") do |count|
90
- count.times { rufus_table.transform(input) }
90
+ count.times { rufus_table.transform!(input) }
91
91
  end
92
92
 
93
93
  x.compare!
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.3.0'
8
+ spec.version = '0.3.1'
9
9
  spec.authors = ['Brett Vickers']
10
10
  spec.email = ['brett@phillips-vickers.com']
11
11
  spec.description = 'CSV based Ruby decision tables.'
data/doc/CSVDecision.html CHANGED
@@ -606,7 +606,7 @@ table.decide(topic: 'finance', region: 'Europe') #=> team_mem
606
606
  </div>
607
607
 
608
608
  <div id="footer">
609
- Generated on Sat Jan 20 15:44:34 2018 by
609
+ Generated on Sun Jan 21 08:56:46 2018 by
610
610
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
611
611
  0.9.12 (ruby-2.4.0).
612
612
  </div>
@@ -133,7 +133,7 @@
133
133
  </div>
134
134
 
135
135
  <div id="footer">
136
- Generated on Sat Jan 20 15:44:35 2018 by
136
+ Generated on Sun Jan 21 08:56:46 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>
@@ -1167,7 +1167,7 @@
1167
1167
  </div>
1168
1168
 
1169
1169
  <div id="footer">
1170
- Generated on Sat Jan 20 15:44:35 2018 by
1170
+ Generated on Sun Jan 21 08:56:46 2018 by
1171
1171
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1172
1172
  0.9.12 (ruby-2.4.0).
1173
1173
  </div>
@@ -697,7 +697,7 @@ of :outs.</p>
697
697
  </div>
698
698
 
699
699
  <div id="footer">
700
- Generated on Sat Jan 20 15:44:35 2018 by
700
+ Generated on Sun Jan 21 08:56:47 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>
@@ -469,7 +469,7 @@ array of arrays. Strips out empty columns/rows and comment cells.</p>
469
469
  </div>
470
470
 
471
471
  <div id="footer">
472
- Generated on Sat Jan 20 15:44:34 2018 by
472
+ Generated on Sun Jan 21 08:56:46 2018 by
473
473
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
474
474
  0.9.12 (ruby-2.4.0).
475
475
  </div>
@@ -308,6 +308,7 @@
308
308
  <pre class="lines">
309
309
 
310
310
 
311
+ 34
311
312
  35
312
313
  36
313
314
  37
@@ -317,24 +318,21 @@
317
318
  41
318
319
  42
319
320
  43
320
- 44
321
- 45
322
- 46</pre>
321
+ 44</pre>
323
322
  </td>
324
323
  <td>
325
- <pre class="code"><span class="info file"># File 'lib/csv_decision/decision.rb', line 35</span>
324
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/decision.rb', line 34</span>
326
325
 
327
326
  <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>
328
327
  <span class='comment'># The result object is a hash of values, and each value will be an array if this is
329
328
  </span> <span class='comment'># a multi-row result for the +first_match: false+ option.
330
329
  </span> <span class='ivar'>@result</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Result.html" title="CSVDecision::Result (class)">Result</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Result.html#initialize-instance_method" title="CSVDecision::Result#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>input:</span> <span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
331
330
 
332
- <span class='comment'># All rows picked by the matching process. An array if +first_match: false+, otherwise
333
- </span> <span class='comment'># a single row.
331
+ <span class='comment'># All rows picked by the matching process. An array if +first_match: false+,
332
+ </span> <span class='comment'># otherwise a single row.
334
333
  </span> <span class='ivar'>@rows_picked</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
335
334
 
336
- <span class='comment'># Relevant table attributes
337
- </span> <span class='ivar'>@first_match</span> <span class='op'>=</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:first_match</span><span class='rbracket'>]</span>
335
+ <span class='ivar'>@first_match</span> <span class='op'>=</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:first_match</span><span class='rbracket'>]</span>
338
336
  <span class='kw'>end</span></pre>
339
337
  </td>
340
338
  </tr>
@@ -461,8 +459,7 @@ hash. Otherwise a copy of the input hash is symbolized.</p>
461
459
  27
462
460
  28
463
461
  29
464
- 30
465
- 31</pre>
462
+ 30</pre>
466
463
  </td>
467
464
  <td>
468
465
  <pre class="code"><span class="info file"># File 'lib/csv_decision/decision.rb', line 18</span>
@@ -475,11 +472,10 @@ hash. Otherwise a copy of the input hash is symbolized.</p>
475
472
  </span> <span class='comment'># calculates the final result
476
473
  </span> <span class='id identifier rubyid_decision'>decision</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="" title="CSVDecision::Decision (class)">Decision</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="#initialize-instance_method" title="CSVDecision::Decision#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>input:</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:hash</span><span class='rbracket'>]</span><span class='rparen'>)</span>
477
474
 
478
- <span class='kw'>if</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_index'>index</span>
479
- <span class='id identifier rubyid_decision'>decision</span><span class='period'>.</span><span class='id identifier rubyid_index'>index</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>input:</span> <span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
480
- <span class='kw'>else</span>
481
- <span class='id identifier rubyid_decision'>decision</span><span class='period'>.</span><span class='id identifier rubyid_scan'>scan</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>hash:</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:hash</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>scan_cols:</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:scan_cols</span><span class='rbracket'>]</span><span class='rparen'>)</span>
482
- <span class='kw'>end</span>
475
+ <span class='comment'># Use the table&#39;s index if present
476
+ </span> <span class='kw'>return</span> <span class='id identifier rubyid_decision'>decision</span><span class='period'>.</span><span class='id identifier rubyid_index'>index</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>input:</span> <span class='id identifier rubyid_input'>input</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_index'>index</span>
477
+
478
+ <span class='id identifier rubyid_decision'>decision</span><span class='period'>.</span><span class='id identifier rubyid_scan'>scan</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>hash:</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:hash</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>scan_cols:</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:scan_cols</span><span class='rbracket'>]</span><span class='rparen'>)</span>
483
479
  <span class='kw'>end</span></pre>
484
480
  </td>
485
481
  </tr>
@@ -592,21 +588,41 @@ hash. Otherwise a copy of the input hash is symbolized.</p>
592
588
  <pre class="lines">
593
589
 
594
590
 
591
+ 62
592
+ 63
593
+ 64
594
+ 65
595
+ 66
596
+ 67
595
597
  68
596
598
  69
597
599
  70
598
600
  71
599
601
  72
600
- 73</pre>
602
+ 73
603
+ 74
604
+ 75
605
+ 76
606
+ 77</pre>
601
607
  </td>
602
608
  <td>
603
- <pre class="code"><span class="info file"># File 'lib/csv_decision/decision.rb', line 68</span>
609
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/decision.rb', line 62</span>
604
610
 
605
611
  <span class='kw'>def</span> <span class='id identifier rubyid_index'>index</span><span class='lparen'>(</span><span class='label'>table:</span><span class='comma'>,</span> <span class='label'>input:</span><span class='rparen'>)</span>
606
612
  <span class='comment'># If the index lookup fails, there&#39;s no match
607
- </span> <span class='kw'>return</span> <span class='lbrace'>{</span><span class='rbrace'>}</span> <span class='kw'>unless</span> <span class='lparen'>(</span><span class='id identifier rubyid_rows'>rows</span> <span class='op'>=</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_index'>index</span><span class='period'>.</span><span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:key</span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='rparen'>)</span>
613
+ </span> <span class='kw'>return</span> <span class='lbrace'>{</span><span class='rbrace'>}</span> <span class='kw'>unless</span> <span class='lparen'>(</span><span class='id identifier rubyid_index_rows'>index_rows</span> <span class='op'>=</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_index'>index</span><span class='period'>.</span><span class='id identifier rubyid_hash'>hash</span><span class='lbracket'>[</span><span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:key</span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='rparen'>)</span>
608
614
 
609
- <span class='id identifier rubyid_index_scan'>index_scan</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>scan_cols:</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:scan_cols</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>hash:</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:hash</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>rows:</span> <span class='id identifier rubyid_rows'>rows</span><span class='rparen'>)</span>
615
+ <span class='kw'>if</span> <span class='ivar'>@first_match</span>
616
+ <span class='id identifier rubyid_index_scan_first_match'>index_scan_first_match</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span>
617
+ <span class='label'>scan_cols:</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:scan_cols</span><span class='rbracket'>]</span><span class='comma'>,</span>
618
+ <span class='label'>hash:</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:hash</span><span class='rbracket'>]</span><span class='comma'>,</span>
619
+ <span class='label'>index_rows:</span> <span class='const'>Array</span><span class='lparen'>(</span><span class='id identifier rubyid_index_rows'>index_rows</span><span class='rparen'>)</span><span class='rparen'>)</span>
620
+ <span class='kw'>else</span>
621
+ <span class='id identifier rubyid_index_scan_accumulate'>index_scan_accumulate</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span>
622
+ <span class='label'>scan_cols:</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:scan_cols</span><span class='rbracket'>]</span><span class='comma'>,</span>
623
+ <span class='label'>hash:</span> <span class='id identifier rubyid_input'>input</span><span class='lbracket'>[</span><span class='symbol'>:hash</span><span class='rbracket'>]</span><span class='comma'>,</span>
624
+ <span class='label'>index_rows:</span> <span class='const'>Array</span><span class='lparen'>(</span><span class='id identifier rubyid_index_rows'>index_rows</span><span class='rparen'>)</span><span class='rparen'>)</span>
625
+ <span class='kw'>end</span>
610
626
  <span class='kw'>end</span></pre>
611
627
  </td>
612
628
  </tr>
@@ -713,25 +729,17 @@ hash. Otherwise a copy of the input hash is symbolized.</p>
713
729
  <pre class="lines">
714
730
 
715
731
 
732
+ 52
733
+ 53
716
734
  54
717
- 55
718
- 56
719
- 57
720
- 58
721
- 59
722
- 60
723
- 61</pre>
735
+ 55</pre>
724
736
  </td>
725
737
  <td>
726
- <pre class="code"><span class="info file"># File 'lib/csv_decision/decision.rb', line 54</span>
738
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/decision.rb', line 52</span>
727
739
 
728
740
  <span class='kw'>def</span> <span class='id identifier rubyid_scan'>scan</span><span class='lparen'>(</span><span class='label'>table:</span><span class='comma'>,</span> <span class='label'>hash:</span><span class='comma'>,</span> <span class='label'>scan_cols:</span><span class='rparen'>)</span>
729
- <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_row'>row</span><span class='comma'>,</span> <span class='id identifier rubyid_index'>index</span><span class='op'>|</span>
730
- <span class='kw'>next</span> <span class='kw'>unless</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_scan_rows'>scan_rows</span><span class='lbracket'>[</span><span class='id identifier rubyid_index'>index</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_match?'>match?</span><span class='lparen'>(</span><span class='label'>row:</span> <span class='id identifier rubyid_row'>row</span><span class='comma'>,</span> <span class='label'>hash:</span> <span class='id identifier rubyid_hash'>hash</span><span class='comma'>,</span> <span class='label'>scan_cols:</span> <span class='id identifier rubyid_scan_cols'>scan_cols</span><span class='rparen'>)</span>
731
- <span class='kw'>return</span> <span class='ivar'>@result</span><span class='period'>.</span><span class='id identifier rubyid_attributes'>attributes</span> <span class='kw'>if</span> <span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='id identifier rubyid_row'>row</span><span class='rparen'>)</span>
732
- <span class='kw'>end</span>
733
-
734
- <span class='ivar'>@rows_picked</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span> <span class='op'>?</span> <span class='lbrace'>{</span><span class='rbrace'>}</span> <span class='op'>:</span> <span class='id identifier rubyid_accumulated_result'>accumulated_result</span>
741
+ <span class='kw'>return</span> <span class='id identifier rubyid_scan_first_match'>scan_first_match</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>hash:</span> <span class='id identifier rubyid_hash'>hash</span><span class='comma'>,</span> <span class='label'>scan_cols:</span> <span class='id identifier rubyid_scan_cols'>scan_cols</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@first_match</span>
742
+ <span class='id identifier rubyid_scan_accumulate'>scan_accumulate</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>hash:</span> <span class='id identifier rubyid_hash'>hash</span><span class='comma'>,</span> <span class='label'>scan_cols:</span> <span class='id identifier rubyid_scan_cols'>scan_cols</span><span class='rparen'>)</span>
735
743
  <span class='kw'>end</span></pre>
736
744
  </td>
737
745
  </tr>
@@ -743,7 +751,7 @@ hash. Otherwise a copy of the input hash is symbolized.</p>
743
751
  </div>
744
752
 
745
753
  <div id="footer">
746
- Generated on Sat Jan 20 15:44:35 2018 by
754
+ Generated on Sun Jan 21 08:56:47 2018 by
747
755
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
748
756
  0.9.12 (ruby-2.4.0).
749
757
  </div>
@@ -281,7 +281,7 @@ We have already determined that this row must be present.</p>
281
281
  </div>
282
282
 
283
283
  <div id="footer">
284
- Generated on Sat Jan 20 15:44:34 2018 by
284
+ Generated on Sun Jan 21 08:56:46 2018 by
285
285
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
286
286
  0.9.12 (ruby-2.4.0).
287
287
  </div>
@@ -416,7 +416,7 @@ the header row.</p>
416
416
  </div>
417
417
 
418
418
  <div id="footer">
419
- Generated on Sat Jan 20 15:44:34 2018 by
419
+ Generated on Sun Jan 21 08:56:46 2018 by
420
420
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
421
421
  0.9.12 (ruby-2.4.0).
422
422
  </div>
@@ -1137,7 +1137,7 @@ type, which is looked up in the above table.</p>
1137
1137
  </div>
1138
1138
 
1139
1139
  <div id="footer">
1140
- Generated on Sat Jan 20 15:44:36 2018 by
1140
+ Generated on Sun Jan 21 08:56:47 2018 by
1141
1141
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1142
1142
  0.9.12 (ruby-2.4.0).
1143
1143
  </div>
@@ -129,7 +129,7 @@
129
129
  </div>
130
130
 
131
131
  <div id="footer">
132
- Generated on Sat Jan 20 15:44:35 2018 by
132
+ Generated on Sun Jan 21 08:56:46 2018 by
133
133
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
134
134
  0.9.12 (ruby-2.4.0).
135
135
  </div>
@@ -133,7 +133,7 @@
133
133
  </div>
134
134
 
135
135
  <div id="footer">
136
- Generated on Sat Jan 20 15:44:35 2018 by
136
+ Generated on Sun Jan 21 08:56:46 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>
@@ -637,7 +637,7 @@ method name - note any spaces will have been replaced with underscores.</p>
637
637
  </div>
638
638
 
639
639
  <div id="footer">
640
- Generated on Sat Jan 20 15:44:34 2018 by
640
+ Generated on Sun Jan 21 08:56:46 2018 by
641
641
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
642
642
  0.9.12 (ruby-2.4.0).
643
643
  </div>
@@ -731,7 +731,7 @@ indexes.</p>
731
731
  </div>
732
732
 
733
733
  <div id="footer">
734
- Generated on Sat Jan 20 15:44:35 2018 by
734
+ Generated on Sun Jan 21 08:56:46 2018 by
735
735
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
736
736
  0.9.12 (ruby-2.4.0).
737
737
  </div>
@@ -116,7 +116,7 @@
116
116
  <li class="public ">
117
117
  <span class="summary_signature">
118
118
 
119
- <a href="#parse-class_method" title="parse (class method)">.<strong>parse</strong>(table:, input:, symbolize_keys:) &#x21d2; Hash{Symbol =&gt; Hash{Symbol=&gt;Object}, Hash{Integer=&gt;Object}} </a>
119
+ <a href="#parse-class_method" title="parse (class method)">.<strong>parse</strong>(table:, input:, symbolize_keys:) &#x21d2; Hash{Symbol=&gt;Object} </a>
120
120
 
121
121
 
122
122
 
@@ -130,11 +130,7 @@
130
130
  <span class="private note title">private</span>
131
131
 
132
132
 
133
- <span class="summary_desc"><div class='inline'>
134
- <p>Returns a hash of two hashes: * hash: either a copy with keys symbolized
135
- or the original input object * scan_cols: Picks out the value in the input
136
- hash for each table input column.</p>
137
- </div></span>
133
+ <span class="summary_desc"><div class='inline'></div></span>
138
134
 
139
135
  </li>
140
136
 
@@ -151,7 +147,7 @@ hash for each table input column.</p>
151
147
  <div class="method_details first">
152
148
  <h3 class="signature first" id="parse-class_method">
153
149
 
154
- .<strong>parse</strong>(table:, input:, symbolize_keys:) &#x21d2; <tt>Hash{Symbol =&gt; Hash{Symbol=&gt;Object}, Hash{Integer=&gt;Object}}</tt>
150
+ .<strong>parse</strong>(table:, input:, symbolize_keys:) &#x21d2; <tt>Hash{Symbol=&gt;Object}</tt>
155
151
 
156
152
 
157
153
 
@@ -164,81 +160,103 @@ hash for each table input column.</p>
164
160
  You should avoid using this method if possible, as it may be removed or be changed in the future.
165
161
  </p>
166
162
 
167
- <p>Returns a hash of two hashes:</p>
168
- <ul><li>
169
- <p>hash: either a copy with keys symbolized or the original input object</p>
170
- </li><li>
171
- <p>scan_cols: Picks out the value in the input hash for each table input
172
- column. Defaults to nil if the key is missing in the input hash.</p>
173
- </li></ul>
174
-
175
163
 
176
164
  </div>
177
165
  </div>
178
166
  <div class="tags">
167
+ <p class="tag_title">Parameters:</p>
168
+ <ul class="param">
179
169
 
180
- <p class="tag_title">Returns:</p>
181
- <ul class="return">
170
+ <li>
171
+
172
+ <span class='name'>table</span>
173
+
174
+
175
+ <span class='type'>(<tt><span class='object_link'><a href="Table.html" title="CSVDecision::Table (class)">CSVDecision::Table</a></span></tt>)</span>
176
+
177
+
178
+
179
+ &mdash;
180
+ <div class='inline'>
181
+ <p>Decision table.</p>
182
+ </div>
183
+
184
+ </li>
185
+
186
+ <li>
187
+
188
+ <span class='name'>input</span>
189
+
190
+
191
+ <span class='type'>(<tt>Hash</tt>)</span>
192
+
193
+
194
+
195
+ &mdash;
196
+ <div class='inline'>
197
+ <p>Input hash (keys may or may not be symbolized)</p>
198
+ </div>
199
+
200
+ </li>
182
201
 
183
202
  <li>
184
203
 
204
+ <span class='name'>symbolize_keys</span>
205
+
185
206
 
186
- <span class='type'>(<tt>Hash{Symbol =&gt; Hash{Symbol=&gt;Object}, Hash{Integer=&gt;Object}}</tt>)</span>
207
+ <span class='type'>(<tt>true</tt>, <tt>false</tt>)</span>
187
208
 
188
209
 
189
210
 
190
211
  &mdash;
191
212
  <div class='inline'>
192
- <p>Returns a hash of two hashes:</p>
193
- <ul><li>
194
- <p>hash: either a copy with keys symbolized or the original input object</p>
195
- </li><li>
196
- <p>scan_cols: Picks out the value in the input hash for each table input
197
- column. Defaults to nil if the key is missing in the input hash.</p>
198
- </li></ul>
213
+ <p>Set to false if keys are symbolized and it&#39;s OK to mutate the input
214
+ hash. Otherwise a copy of the input hash is symbolized.</p>
199
215
  </div>
200
216
 
201
217
  </li>
202
218
 
203
219
  </ul>
204
220
 
221
+ <p class="tag_title">Returns:</p>
222
+ <ul class="return">
223
+
224
+ <li>
225
+
226
+
227
+ <span class='type'>(<tt>Hash{Symbol=&gt;Object}</tt>)</span>
228
+
229
+
230
+
231
+ </li>
232
+
233
+ </ul>
234
+
205
235
  </div><table class="source_code">
206
236
  <tr>
207
237
  <td>
208
238
  <pre class="lines">
209
239
 
210
240
 
241
+ 13
242
+ 14
243
+ 15
244
+ 16
211
245
  17
212
246
  18
213
247
  19
214
- 20
215
- 21
216
- 22
217
- 23
218
- 24
219
- 25
220
- 26
221
- 27
222
- 28
223
- 29
224
- 30</pre>
248
+ 20</pre>
225
249
  </td>
226
250
  <td>
227
- <pre class="code"><span class="info file"># File 'lib/csv_decision/input.rb', line 17</span>
251
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/input.rb', line 13</span>
228
252
 
229
253
  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='label'>table:</span><span class='comma'>,</span> <span class='label'>input:</span><span class='comma'>,</span> <span class='label'>symbolize_keys:</span><span class='rparen'>)</span>
230
254
  <span class='id identifier rubyid_validate'>validate</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
231
255
 
232
- <span class='id identifier rubyid_hash'>hash</span><span class='comma'>,</span> <span class='id identifier rubyid_scan_cols'>scan_cols</span> <span class='op'>=</span>
233
- <span class='id identifier rubyid_parse_input'>parse_input</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>input:</span> <span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='op'>?</span> <span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='op'>:</span> <span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
256
+ <span class='id identifier rubyid_parsed_input'>parsed_input</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_input'>parse_input</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>input:</span> <span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='op'>?</span> <span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='op'>:</span> <span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
234
257
 
235
- <span class='lbrace'>{</span>
236
- <span class='comment'># We can freeze the input hash for safety if we made our own copy.
237
- </span> <span class='label'>hash:</span> <span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span> <span class='op'>?</span> <span class='id identifier rubyid_hash'>hash</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span> <span class='op'>:</span> <span class='id identifier rubyid_hash'>hash</span><span class='comma'>,</span>
238
- <span class='label'>scan_cols:</span> <span class='id identifier rubyid_scan_cols'>scan_cols</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span><span class='comma'>,</span>
239
- <span class='comment'># Build the index key if this table is indexed.
240
- </span> <span class='label'>key:</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_index'>index</span> <span class='op'>?</span> <span class='id identifier rubyid_parse_key'>parse_key</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>hash:</span> <span class='id identifier rubyid_hash'>hash</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
241
- <span class='rbrace'>}</span>
258
+ <span class='id identifier rubyid_parsed_input'>parsed_input</span><span class='lbracket'>[</span><span class='symbol'>:key</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_key'>parse_key</span><span class='lparen'>(</span><span class='label'>table:</span> <span class='id identifier rubyid_table'>table</span><span class='comma'>,</span> <span class='label'>hash:</span> <span class='id identifier rubyid_parsed_input'>parsed_input</span><span class='lbracket'>[</span><span class='symbol'>:hash</span><span class='rbracket'>]</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_index'>index</span>
259
+ <span class='id identifier rubyid_parsed_input'>parsed_input</span>
242
260
  <span class='kw'>end</span></pre>
243
261
  </td>
244
262
  </tr>
@@ -250,7 +268,7 @@ column. Defaults to nil if the key is missing in the input hash.</p>
250
268
  </div>
251
269
 
252
270
  <div id="footer">
253
- Generated on Sat Jan 20 15:44:34 2018 by
271
+ Generated on Sun Jan 21 08:56:46 2018 by
254
272
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
255
273
  0.9.12 (ruby-2.4.0).
256
274
  </div>
@@ -281,7 +281,7 @@
281
281
  </div>
282
282
 
283
283
  <div id="footer">
284
- Generated on Sat Jan 20 15:44:34 2018 by
284
+ Generated on Sun Jan 21 08:56:46 2018 by
285
285
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
286
286
  0.9.12 (ruby-2.4.0).
287
287
  </div>
@@ -1350,7 +1350,7 @@ nil.</p>
1350
1350
  </div>
1351
1351
 
1352
1352
  <div id="footer">
1353
- Generated on Sat Jan 20 15:44:35 2018 by
1353
+ Generated on Sun Jan 21 08:56:46 2018 by
1354
1354
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1355
1355
  0.9.12 (ruby-2.4.0).
1356
1356
  </div>
@@ -474,7 +474,7 @@ some type of function.</p>
474
474
  </div>
475
475
 
476
476
  <div id="footer">
477
- Generated on Sat Jan 20 15:44:36 2018 by
477
+ Generated on Sun Jan 21 08:56:47 2018 by
478
478
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
479
479
  0.9.12 (ruby-2.4.0).
480
480
  </div>
@@ -501,7 +501,7 @@ some type of function.</p>
501
501
  </div>
502
502
 
503
503
  <div id="footer">
504
- Generated on Sat Jan 20 15:44:36 2018 by
504
+ Generated on Sun Jan 21 08:56:47 2018 by
505
505
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
506
506
  0.9.12 (ruby-2.4.0).
507
507
  </div>
@@ -493,7 +493,7 @@ some type of function.</p>
493
493
  </div>
494
494
 
495
495
  <div id="footer">
496
- Generated on Sat Jan 20 15:44:36 2018 by
496
+ Generated on Sun Jan 21 08:56:47 2018 by
497
497
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
498
498
  0.9.12 (ruby-2.4.0).
499
499
  </div>
@@ -497,7 +497,7 @@ some type of function.</p>
497
497
  </div>
498
498
 
499
499
  <div id="footer">
500
- Generated on Sat Jan 20 15:44:35 2018 by
500
+ Generated on Sun Jan 21 08:56:47 2018 by
501
501
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
502
502
  0.9.12 (ruby-2.4.0).
503
503
  </div>
@@ -411,7 +411,7 @@ some type of function.</p>
411
411
  </div>
412
412
 
413
413
  <div id="footer">
414
- Generated on Sat Jan 20 15:44:36 2018 by
414
+ Generated on Sun Jan 21 08:56:47 2018 by
415
415
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
416
416
  0.9.12 (ruby-2.4.0).
417
417
  </div>
@@ -481,7 +481,7 @@ some type of function.</p>
481
481
  </div>
482
482
 
483
483
  <div id="footer">
484
- Generated on Sat Jan 20 15:44:36 2018 by
484
+ Generated on Sun Jan 21 08:56:47 2018 by
485
485
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
486
486
  0.9.12 (ruby-2.4.0).
487
487
  </div>
@@ -694,7 +694,7 @@ hash keys (which are always symbolized).</p>
694
694
  </div>
695
695
 
696
696
  <div id="footer">
697
- Generated on Sat Jan 20 15:44:35 2018 by
697
+ Generated on Sun Jan 21 08:56:47 2018 by
698
698
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
699
699
  0.9.12 (ruby-2.4.0).
700
700
  </div>
@@ -369,7 +369,7 @@ some type of function.</p>
369
369
  </div>
370
370
 
371
371
  <div id="footer">
372
- Generated on Sat Jan 20 15:44:36 2018 by
372
+ Generated on Sun Jan 21 08:56:47 2018 by
373
373
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
374
374
  0.9.12 (ruby-2.4.0).
375
375
  </div>
@@ -415,7 +415,7 @@ some type of function.</p>
415
415
  </div>
416
416
 
417
417
  <div id="footer">
418
- Generated on Sat Jan 20 15:44:36 2018 by
418
+ Generated on Sun Jan 21 08:56:47 2018 by
419
419
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
420
420
  0.9.12 (ruby-2.4.0).
421
421
  </div>
@@ -433,7 +433,7 @@ set.</p>
433
433
  </div>
434
434
 
435
435
  <div id="footer">
436
- Generated on Sat Jan 20 15:44:34 2018 by
436
+ Generated on Sun Jan 21 08:56:46 2018 by
437
437
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
438
438
  0.9.12 (ruby-2.4.0).
439
439
  </div>
@@ -272,7 +272,7 @@
272
272
  </div>
273
273
 
274
274
  <div id="footer">
275
- Generated on Sat Jan 20 15:44:34 2018 by
275
+ Generated on Sun Jan 21 08:56:46 2018 by
276
276
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
277
277
  0.9.12 (ruby-2.4.0).
278
278
  </div>
@@ -483,6 +483,9 @@ result, along with the partial result required to evaluate functions.</p>
483
483
  <pre class="code"><span class="info file"># File 'lib/csv_decision/result.rb', line 25</span>
484
484
 
485
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>
486
+ <span class='comment'># Attributes hash contains the output decision key value pairs
487
+ </span> <span class='ivar'>@attributes</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
488
+
486
489
  <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
490
  <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>
488
491
  <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>
@@ -492,10 +495,7 @@ result, along with the partial result required to evaluate functions.</p>
492
495
  </span> <span class='comment'># have the same symbol as an input hash key.
493
496
  </span> <span class='comment'># However, the rest of this hash is mutated as output column evaluation results
494
497
  </span> <span class='comment'># are accumulated.
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>
496
-
497
- <span class='comment'># Attributes hash contains the output decision key value pairs
498
- </span> <span class='ivar'>@attributes</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
498
+ </span> <span class='ivar'>@partial_result</span> <span class='op'>=</span> <span class='id identifier rubyid_input'>input</span><span class='period'>.</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>
499
499
  <span class='kw'>end</span></pre>
500
500
  </td>
501
501
  </tr>
@@ -1134,7 +1134,7 @@ result, along with the partial result required to evaluate functions.</p>
1134
1134
  </div>
1135
1135
 
1136
1136
  <div id="footer">
1137
- Generated on Sat Jan 20 15:44:35 2018 by
1137
+ Generated on Sun Jan 21 08:56:46 2018 by
1138
1138
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1139
1139
  0.9.12 (ruby-2.4.0).
1140
1140
  </div>
@@ -858,7 +858,7 @@ non-string constant.</p>
858
858
  </div>
859
859
 
860
860
  <div id="footer">
861
- Generated on Sat Jan 20 15:44:35 2018 by
861
+ Generated on Sun Jan 21 08:56:47 2018 by
862
862
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
863
863
  0.9.12 (ruby-2.4.0).
864
864
  </div>
@@ -514,22 +514,12 @@ and last row index given.</p>
514
514
  81
515
515
  82
516
516
  83
517
- 84
518
- 85
519
- 86
520
- 87
521
- 88
522
- 89</pre>
517
+ 84</pre>
523
518
  </td>
524
519
  <td>
525
520
  <pre class="code"><span class="info file"># File 'lib/csv_decision/table.rb', line 79</span>
526
521
 
527
522
  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
528
- <span class='ivar'>@columns</span> <span class='op'>=</span> <span class='kw'>nil</span>
529
- <span class='ivar'>@file</span> <span class='op'>=</span> <span class='kw'>nil</span>
530
- <span class='ivar'>@index</span> <span class='op'>=</span> <span class='kw'>nil</span>
531
- <span class='ivar'>@options</span> <span class='op'>=</span> <span class='kw'>nil</span>
532
- <span class='ivar'>@outs_functions</span> <span class='op'>=</span> <span class='kw'>nil</span>
533
523
  <span class='ivar'>@outs_rows</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
534
524
  <span class='ivar'>@if_rows</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
535
525
  <span class='ivar'>@rows</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
@@ -1380,7 +1370,7 @@ and last row index given.</p>
1380
1370
  </div>
1381
1371
 
1382
1372
  <div id="footer">
1383
- Generated on Sat Jan 20 15:44:35 2018 by
1373
+ Generated on Sun Jan 21 08:56:46 2018 by
1384
1374
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1385
1375
  0.9.12 (ruby-2.4.0).
1386
1376
  </div>
@@ -133,7 +133,7 @@
133
133
  </div>
134
134
 
135
135
  <div id="footer">
136
- Generated on Sat Jan 20 15:44:35 2018 by
136
+ Generated on Sun Jan 21 08:56:46 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>
@@ -412,7 +412,7 @@ only required at table load time.</p>
412
412
  </div>
413
413
 
414
414
  <div id="footer">
415
- Generated on Sat Jan 20 15:44:34 2018 by
415
+ Generated on Sun Jan 21 08:56:46 2018 by
416
416
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
417
417
  0.9.12 (ruby-2.4.0).
418
418
  </div>
data/doc/_index.html CHANGED
@@ -440,7 +440,7 @@
440
440
  </div>
441
441
 
442
442
  <div id="footer">
443
- Generated on Sat Jan 20 15:44:33 2018 by
443
+ Generated on Sun Jan 21 08:56:44 2018 by
444
444
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
445
445
  0.9.12 (ruby-2.4.0).
446
446
  </div>
data/doc/file.README.html CHANGED
@@ -385,7 +385,7 @@ href="./LICENSE">LICENSE</a> document for more information.</p>
385
385
  </div></div>
386
386
 
387
387
  <div id="footer">
388
- Generated on Sat Jan 20 15:44:34 2018 by
388
+ Generated on Sun Jan 21 08:56:46 2018 by
389
389
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
390
390
  0.9.12 (ruby-2.4.0).
391
391
  </div>
data/doc/index.html CHANGED
@@ -385,7 +385,7 @@ href="./LICENSE">LICENSE</a> document for more information.</p>
385
385
  </div></div>
386
386
 
387
387
  <div id="footer">
388
- Generated on Sat Jan 20 15:44:34 2018 by
388
+ Generated on Sun Jan 21 08:56:45 2018 by
389
389
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
390
390
  0.9.12 (ruby-2.4.0).
391
391
  </div>
@@ -100,7 +100,7 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Sat Jan 20 15:44:34 2018 by
103
+ Generated on Sun Jan 21 08:56:46 2018 by
104
104
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
105
  0.9.12 (ruby-2.4.0).
106
106
  </div>
@@ -23,11 +23,10 @@ module CSVDecision
23
23
  # calculates the final result
24
24
  decision = Decision.new(table: table, input: input[:hash])
25
25
 
26
- if table.index
27
- decision.index(table: table, input: input)
28
- else
29
- decision.scan(table: table, hash: input[:hash], scan_cols: input[:scan_cols])
30
- end
26
+ # Use the table's index if present
27
+ return decision.index(table: table, input: input) if table.index
28
+
29
+ decision.scan(table: table, hash: input[:hash], scan_cols: input[:scan_cols])
31
30
  end
32
31
 
33
32
  # @param table [CSVDecision::Table] Decision table being processed.
@@ -37,11 +36,10 @@ module CSVDecision
37
36
  # a multi-row result for the +first_match: false+ option.
38
37
  @result = Result.new(table: table, input: input)
39
38
 
40
- # All rows picked by the matching process. An array if +first_match: false+, otherwise
41
- # a single row.
39
+ # All rows picked by the matching process. An array if +first_match: false+,
40
+ # otherwise a single row.
42
41
  @rows_picked = []
43
42
 
44
- # Relevant table attributes
45
43
  @first_match = table.options[:first_match]
46
44
  end
47
45
 
@@ -52,12 +50,8 @@ module CSVDecision
52
50
  # @param scan_cols [Hash{Index=>Object}] Input column values to scan.
53
51
  # @return [Hash{Symbol=>Object}] Decision result.
54
52
  def scan(table:, hash:, scan_cols:)
55
- table.each do |row, index|
56
- next unless table.scan_rows[index].match?(row: row, hash: hash, scan_cols: scan_cols)
57
- return @result.attributes if add(row)
58
- end
59
-
60
- @rows_picked.empty? ? {} : accumulated_result
53
+ return scan_first_match(table: table, hash: hash, scan_cols: scan_cols) if @first_match
54
+ scan_accumulate(table: table, hash: hash, scan_cols: scan_cols)
61
55
  end
62
56
 
63
57
  # Use an index to scan the decision table up against the input hash.
@@ -67,37 +61,66 @@ module CSVDecision
67
61
  # @return [{Symbol=>Object}] Decision result.
68
62
  def index(table:, input:)
69
63
  # If the index lookup fails, there's no match
70
- return {} unless (rows = table.index.hash[input[:key]])
64
+ return {} unless (index_rows = table.index.hash[input[:key]])
71
65
 
72
- index_scan(table: table, scan_cols: input[:scan_cols], hash: input[:hash], rows: Array(rows))
66
+ if @first_match
67
+ index_scan_first_match(table: table,
68
+ scan_cols: input[:scan_cols],
69
+ hash: input[:hash],
70
+ index_rows: Array(index_rows))
71
+ else
72
+ index_scan_accumulate(table: table,
73
+ scan_cols: input[:scan_cols],
74
+ hash: input[:hash],
75
+ index_rows: Array(index_rows))
76
+ end
73
77
  end
74
78
 
75
79
  private
76
80
 
77
- def index_scan(table:, scan_cols:, hash:, rows:)
78
- rows.each do |start_row, end_row|
81
+ def scan_first_match(table:, hash:, scan_cols:)
82
+ table.each do |row, index|
83
+ next unless table.scan_rows[index].match?(row: row, hash: hash, scan_cols: scan_cols)
84
+
85
+ return @result.attributes if first_match(row)
86
+ end
87
+
88
+ {}
89
+ end
90
+
91
+ def scan_accumulate(table:, hash:, scan_cols:)
92
+ table.each do |row, index|
93
+ next unless table.scan_rows[index].match?(row: row, hash: hash, scan_cols: scan_cols)
94
+ # Accumulate output rows
95
+ @rows_picked << row
96
+ @result.accumulate_outs(row)
97
+ end
98
+
99
+ @rows_picked.empty? ? {} : accumulated_result
100
+ end
101
+
102
+ def index_scan_first_match(table:, scan_cols:, hash:, index_rows:)
103
+ index_rows.each do |start_row, end_row|
79
104
  table.each(start_row, end_row || start_row) do |row, index|
80
105
  next unless table.scan_rows[index].match?(row: row, hash: hash, scan_cols: scan_cols)
81
- return @result.attributes if add(row)
106
+ return @result.attributes if first_match(row)
82
107
  end
83
108
  end
84
109
 
85
- @rows_picked.empty? ? {} : accumulated_result
110
+ {}
86
111
  end
87
112
 
88
- # Add a matched row to the decision object being built.
89
- #
90
- # @param row [Array] Data row.
91
- # @return [false, Hash]
92
- def add(row)
93
- return add_first_match(row) if @first_match
94
-
95
- # Accumulate output rows
96
- @rows_picked << row
97
- @result.accumulate_outs(row)
113
+ def index_scan_accumulate(table:, scan_cols:, hash:, index_rows:)
114
+ index_rows.each do |start_row, end_row|
115
+ table.each(start_row, end_row || start_row) do |row, index|
116
+ next unless table.scan_rows[index].match?(row: row, hash: hash, scan_cols: scan_cols)
117
+ # Accumulate output rows
118
+ @rows_picked << row
119
+ @result.accumulate_outs(row)
120
+ end
121
+ end
98
122
 
99
- # Not done
100
- false
123
+ @rows_picked.empty? ? {} : accumulated_result
101
124
  end
102
125
 
103
126
  def accumulated_result
@@ -124,7 +147,7 @@ module CSVDecision
124
147
  end
125
148
  end
126
149
 
127
- def add_first_match(row)
150
+ def first_match(row)
128
151
  # This decision row may contain procs, which if present will need to be evaluated.
129
152
  # If this row contains if: columns then this row may be filtered out, in which case
130
153
  # this method call will return false.
@@ -8,33 +8,16 @@ module CSVDecision
8
8
  # Parse the input hash.
9
9
  # @api private
10
10
  module Input
11
- # @param (see Decide.decide)
12
- # @return [Hash{Symbol => Hash{Symbol=>Object}, Hash{Integer=>Object}}]
13
- # Returns a hash of two hashes:
14
- # * hash: either a copy with keys symbolized or the original input object
15
- # * scan_cols: Picks out the value in the input hash for each table input column.
16
- # Defaults to nil if the key is missing in the input hash.
11
+ # @param (see Decision.make)
12
+ # @return [Hash{Symbol=>Object}]
17
13
  def self.parse(table:, input:, symbolize_keys:)
18
14
  validate(input)
19
15
 
20
16
  parsed_input = parse_input(table: table, input: symbolize_keys ? input.symbolize_keys : input)
21
17
 
22
- key = table.index ? parse_key(table: table, hash: parsed_input[:hash]) : nil
23
-
24
- result(symbolize_keys: symbolize_keys, input: parsed_input, key: key)
25
- end
26
-
27
- def self.result(symbolize_keys:, input:, key:)
28
- hash = input[:hash]
29
- {
30
- # We can freeze the input hash for safety if we made our own copy.
31
- hash: symbolize_keys ? hash.freeze : hash,
32
- scan_cols: input[:scan_cols].freeze,
33
- # Build the index key if this table is indexed.
34
- key: key
35
- }
18
+ parsed_input[:key] = parse_key(table: table, hash: parsed_input[:hash]) if table.index
19
+ parsed_input
36
20
  end
37
- private_class_method :result
38
21
 
39
22
  def self.parse_key(table:, hash:)
40
23
  return scan_key(table: table, hash: hash) if table.index.columns.count == 1
@@ -74,7 +57,6 @@ module CSVDecision
74
57
 
75
58
  parse_defaulted(table: table, input: input, defaulted_columns: defaulted_columns)
76
59
  end
77
-
78
60
  private_class_method :parse_input
79
61
 
80
62
  def self.parse_cells(table:, input:)
@@ -87,7 +69,6 @@ module CSVDecision
87
69
 
88
70
  { hash: input, scan_cols: scan_cols }
89
71
  end
90
-
91
72
  private_class_method :parse_cells
92
73
 
93
74
  def self.parse_defaulted(table:, input:, defaulted_columns:)
@@ -105,7 +86,6 @@ module CSVDecision
105
86
 
106
87
  { hash: input, scan_cols: scan_cols }
107
88
  end
108
-
109
89
  private_class_method :parse_defaulted
110
90
 
111
91
  def self.default_value(default:, input:, column:)
@@ -121,13 +101,11 @@ module CSVDecision
121
101
  # or else a constant.
122
102
  eval_default(default.function, input)
123
103
  end
124
-
125
104
  private_class_method :default_value
126
105
 
127
106
  def self.default_if?(set_if, value)
128
107
  set_if == true || (value.respond_to?(set_if) && value.send(set_if))
129
108
  end
130
-
131
109
  private_class_method :default_if?
132
110
 
133
111
  # Expression may be a Proc that needs evaluating against the input hash,
@@ -135,7 +113,6 @@ module CSVDecision
135
113
  def self.eval_default(expression, input)
136
114
  expression.is_a?(::Proc) ? expression[input] : expression
137
115
  end
138
-
139
116
  private_class_method :eval_default
140
117
  end
141
118
  end
@@ -23,6 +23,9 @@ module CSVDecision
23
23
 
24
24
  # (see Decision.initialize)
25
25
  def initialize(table:, input:)
26
+ # Attributes hash contains the output decision key value pairs
27
+ @attributes = {}
28
+
26
29
  @outs = table.columns.outs
27
30
  @outs_functions = table.outs_functions
28
31
  @if_columns = table.columns.ifs
@@ -32,10 +35,7 @@ module CSVDecision
32
35
  # have the same symbol as an input hash key.
33
36
  # However, the rest of this hash is mutated as output column evaluation results
34
37
  # are accumulated.
35
- @partial_result = input&.slice(*table.columns.input_keys) if @outs_functions
36
-
37
- # Attributes hash contains the output decision key value pairs
38
- @attributes = {}
38
+ @partial_result = input.slice(*table.columns.input_keys) if @outs_functions
39
39
  end
40
40
 
41
41
  # Common case for building a single row result is just copying output column values to the
@@ -92,7 +92,7 @@ module CSVDecision
92
92
  # or filtered by the if: column conditions.
93
93
  def single_row_result
94
94
  @if_columns.each_key do |col|
95
- return nil unless @attributes[col]
95
+ return false unless @attributes[col]
96
96
 
97
97
  # Remove the if: column from the final result hash.
98
98
  @attributes.delete(col)
@@ -77,11 +77,6 @@ module CSVDecision
77
77
 
78
78
  # @api private
79
79
  def initialize
80
- @columns = nil
81
- @file = nil
82
- @index = nil
83
- @options = nil
84
- @outs_functions = nil
85
80
  @outs_rows = []
86
81
  @if_rows = []
87
82
  @rows = []
@@ -30,7 +30,6 @@ describe CSVDecision::Input do
30
30
 
31
31
  expect(result).to eql expected
32
32
  expect(result[:hash]).not_to equal expected[:hash]
33
- expect(result[:hash].frozen?).to eq true
34
33
  end
35
34
 
36
35
  it 'processes input hash with symbolize_keys: false' do
@@ -52,6 +51,5 @@ describe CSVDecision::Input do
52
51
 
53
52
  expect(result).to eql expected
54
53
  expect(result[:hash]).to equal expected[:hash]
55
- expect(result[:hash].frozen?).to eq false
56
54
  end
57
55
  end
@@ -522,6 +522,8 @@ describe CSVDecision::Table do
522
522
 
523
523
  expect(table.send(method, topic: 'politics', region: 'Arctic'))
524
524
  .to eq(team_member: %w[Henry Zach])
525
+ expect(table.send(method, topic: 'culture', region: 'America'))
526
+ .to eq({})
525
527
  end
526
528
  end
527
529
  end
@@ -556,6 +558,7 @@ describe CSVDecision::Table do
556
558
  expect(table.send(method, number: 1, type: 'integer', input: 'none')).to eq(output: 0)
557
559
  expect(table.send(method, number: nil, type: 'string', input: 'one')).to eq(output: nil)
558
560
  expect(table.send(method, string: '1', type: 'string', input: 'one')).to eq(output: '1')
561
+ expect(table.send(method, number: '1', type: 'string', input: 'one')).to eq({})
559
562
  end
560
563
  end
561
564
  end
@@ -1,12 +1,12 @@
1
- in:topic,in:region,out:team_member
2
- sports,Europe,Alice
3
- sports,,Bob
4
- finance,America,Charlie
5
- finance,Europe,Donald
6
- finance,,Ernest
7
- politics,Asia,Fujio
8
- politics,America,Gilbert
9
- politics,,Henry
10
- sports,,Zach
11
- finance,,Zach
1
+ in:topic,in:region,out:team_member
2
+ sports,Europe,Alice
3
+ sports,,Bob
4
+ finance,America,Charlie
5
+ finance,Europe,Donald
6
+ finance,,Ernest
7
+ politics,Asia,Fujio
8
+ politics,America,Gilbert
9
+ politics,,Henry
10
+ sports,,Zach
11
+ finance,,Zach
12
12
  politics,,Zach
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_decision
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Vickers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-20 00:00:00.000000000 Z
11
+ date: 2018-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport