csv_decision 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +4 -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 +1 -1
  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 +1 -1
  19. data/doc/CSVDecision/Load.html +1 -1
  20. data/doc/CSVDecision/Matchers.html +136 -56
  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 +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 +1 -1
  28. data/doc/CSVDecision/Matchers/Range.html +1 -1
  29. data/doc/CSVDecision/Matchers/Symbol.html +31 -20
  30. data/doc/CSVDecision/Options.html +1 -1
  31. data/doc/CSVDecision/Parse.html +1 -1
  32. data/doc/CSVDecision/Result.html +1 -1
  33. data/doc/CSVDecision/ScanRow.html +1 -1
  34. data/doc/CSVDecision/Table.html +1 -1
  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 +7 -3
  39. data/doc/index.html +7 -3
  40. data/doc/top-level-namespace.html +1 -1
  41. data/lib/csv_decision/matchers.rb +12 -2
  42. data/lib/csv_decision/matchers/symbol.rb +57 -8
  43. data/spec/csv_decision/examples_spec.rb +17 -0
  44. data/spec/csv_decision/table_spec.rb +32 -4
  45. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb96b1d411143422f0f4c1f97387eedc8201dde3
4
- data.tar.gz: d8e8f472aef2fd94cd27f5e0f88dc367059b1622
3
+ metadata.gz: 7238268643ad9dc69c91b0367550cd0ed2577b7d
4
+ data.tar.gz: d00d7a55a444b8026cb2bf477ce2812f16c2084d
5
5
  SHA512:
6
- metadata.gz: 2a37235cdddef0ccc57f09a11b07fe90a913bc7f7c6d917ce25eb8ad4f50ab511814079e0085f9dc705685fa34345cfbac77ae916139ef3a9e3a295fa9b7a714
7
- data.tar.gz: 46dd898df746be2efbef4a1d5a9372067ee3a43bfaebe54ad9a212b82b615a2c28d4ac0fb60a52c8428e6f81b9eb7073464daccb7d4a64c67754280c498203e6
6
+ metadata.gz: 89b76ce96dd906ab748158e6a96bb0f02e40abf6b4df4a5fafa5809dac1663a1b7ea97cbbc1cdfad7e10456e5b78b3e674e9e2032dcd24ac6009d8dcc8467b82
7
+ data.tar.gz: bde8179729614e89c2fa5fa5861e5ca55fe34a2038b752e3d4e27968f9eb83fb8a5979d18bd5353089482e54315355190e28792a1008618d169267df15a7790c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.4.0, 28 January 2018.
2
+ *Additions*
3
+ - Input columns may now use 0-arity Ruby methods to implement conditional logic.
4
+ For example `.present?` or `nil?`. Negation is also supported - e.g., `!.nil?`.
5
+
1
6
  ## v0.3.2, 28 January 2018.
2
7
  *Changes*
3
8
  - Refactor code and update documentation.
data/README.md CHANGED
@@ -196,7 +196,10 @@ may be simplified to:
196
196
  , no
197
197
  DATA
198
198
  ```
199
- These comparison operators are also supported: `!=`, `>`, `>=`, `<`, `<=`.
199
+ These comparison operators are also supported: `!=`, `>`, `>=`, `<`, `<=`.
200
+ In addition, you can also apply a Ruby 0-arity method - e.g., `.present?` or `.nil?`. Negation is
201
+ also supported - e.g., `!.nil?`.
202
+
200
203
  For more simple examples see `spec/csv_decision/examples_spec.rb`.
201
204
 
202
205
  #### Input `guard` conditions
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.2'
8
+ spec.version = '0.4.0'
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
@@ -611,7 +611,7 @@ table.decide(topic: &#39;finance&#39;, region: &#39;Europe&#39;) #=&gt; team_mem
611
611
  </div>
612
612
 
613
613
  <div id="footer">
614
- Generated on Sun Jan 28 11:58:37 2018 by
614
+ Generated on Sun Jan 28 14:41:48 2018 by
615
615
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
616
616
  0.9.12 (ruby-2.4.0).
617
617
  </div>
@@ -133,7 +133,7 @@
133
133
  </div>
134
134
 
135
135
  <div id="footer">
136
- Generated on Sun Jan 28 11:58:38 2018 by
136
+ Generated on Sun Jan 28 14:41:48 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 Sun Jan 28 11:58:38 2018 by
1170
+ Generated on Sun Jan 28 14:41:49 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 Sun Jan 28 11:58:39 2018 by
700
+ Generated on Sun Jan 28 14:41:49 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 Sun Jan 28 11:58:38 2018 by
472
+ Generated on Sun Jan 28 14:41:48 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>
@@ -655,7 +655,7 @@ hash. Otherwise a copy of the input hash is symbolized.</p>
655
655
  </div>
656
656
 
657
657
  <div id="footer">
658
- Generated on Sun Jan 28 11:58:39 2018 by
658
+ Generated on Sun Jan 28 14:41:49 2018 by
659
659
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
660
660
  0.9.12 (ruby-2.4.0).
661
661
  </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 Sun Jan 28 11:58:38 2018 by
284
+ Generated on Sun Jan 28 14:41:48 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 Sun Jan 28 11:58:38 2018 by
419
+ Generated on Sun Jan 28 14:41:48 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 Sun Jan 28 11:58:39 2018 by
1140
+ Generated on Sun Jan 28 14:41:49 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 Sun Jan 28 11:58:38 2018 by
132
+ Generated on Sun Jan 28 14:41:48 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 Sun Jan 28 11:58:38 2018 by
136
+ Generated on Sun Jan 28 14:41:48 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 Sun Jan 28 11:58:38 2018 by
640
+ Generated on Sun Jan 28 14:41:48 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 Sun Jan 28 11:58:38 2018 by
734
+ Generated on Sun Jan 28 14:41:48 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>
@@ -268,7 +268,7 @@ hash. Otherwise a copy of the input hash is symbolized.</p>
268
268
  </div>
269
269
 
270
270
  <div id="footer">
271
- Generated on Sun Jan 28 11:58:38 2018 by
271
+ Generated on Sun Jan 28 14:41:48 2018 by
272
272
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
273
273
  0.9.12 (ruby-2.4.0).
274
274
  </div>
@@ -286,7 +286,7 @@
286
286
  </div>
287
287
 
288
288
  <div id="footer">
289
- Generated on Sun Jan 28 11:58:38 2018 by
289
+ Generated on Sun Jan 28 14:41:48 2018 by
290
290
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
291
291
  0.9.12 (ruby-2.4.0).
292
292
  </div>
@@ -150,6 +150,46 @@
150
150
  </dt>
151
151
  <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>!</span><span class='tstring_end'>&#39;</span></span></pre></dd>
152
152
 
153
+ <dt id="INEQUALITY-constant" class="">INEQUALITY =
154
+ <div class="docstring">
155
+ <div class="discussion">
156
+ <p class="note private">
157
+ <strong>This constant is part of a private API.</strong>
158
+ You should avoid using this constant if possible, as it may be removed or be changed in the future.
159
+ </p>
160
+
161
+ <p>Symbols used for inequality</p>
162
+
163
+
164
+ </div>
165
+ </div>
166
+ <div class="tags">
167
+
168
+
169
+ </div>
170
+ </dt>
171
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>!=|!</span><span class='tstring_end'>&#39;</span></span></pre></dd>
172
+
173
+ <dt id="INEQUALITY_RE-constant" class="">INEQUALITY_RE =
174
+ <div class="docstring">
175
+ <div class="discussion">
176
+ <p class="note private">
177
+ <strong>This constant is part of a private API.</strong>
178
+ You should avoid using this constant if possible, as it may be removed or be changed in the future.
179
+ </p>
180
+
181
+ <p>Match string for inequality</p>
182
+
183
+
184
+ </div>
185
+ </div>
186
+ <div class="tags">
187
+
188
+
189
+ </div>
190
+ </dt>
191
+ <dd><pre class="code"><span class='id identifier rubyid_regexp'>regexp</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="#INEQUALITY-constant" title="CSVDecision::Matchers::INEQUALITY (constant)">INEQUALITY</a></span></span><span class='rparen'>)</span></pre></dd>
192
+
153
193
  <dt id="EQUALS-constant" class="">EQUALS =
154
194
  <div class="docstring">
155
195
  <div class="discussion">
@@ -158,8 +198,8 @@
158
198
  You should avoid using this constant if possible, as it may be removed or be changed in the future.
159
199
  </p>
160
200
 
161
- <p>Cell constants and functions specified by prefixing the value with one of
162
- these 3 symbols.</p>
201
+ <p>Equality, cell constants and functions specified by prefixing the value
202
+ with one of these 3 symbols.</p>
163
203
 
164
204
 
165
205
  </div>
@@ -171,6 +211,46 @@ these 3 symbols.</p>
171
211
  </dt>
172
212
  <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>==|:=|=</span><span class='tstring_end'>&#39;</span></span></pre></dd>
173
213
 
214
+ <dt id="EQUALS_RE-constant" class="">EQUALS_RE =
215
+ <div class="docstring">
216
+ <div class="discussion">
217
+ <p class="note private">
218
+ <strong>This constant is part of a private API.</strong>
219
+ You should avoid using this constant if possible, as it may be removed or be changed in the future.
220
+ </p>
221
+
222
+ <p>Match string for equality</p>
223
+
224
+
225
+ </div>
226
+ </div>
227
+ <div class="tags">
228
+
229
+
230
+ </div>
231
+ </dt>
232
+ <dd><pre class="code"><span class='id identifier rubyid_regexp'>regexp</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="#EQUALS-constant" title="CSVDecision::Matchers::EQUALS (constant)">EQUALS</a></span></span><span class='rparen'>)</span></pre></dd>
233
+
234
+ <dt id="METHOD_NAME_RE-constant" class="">METHOD_NAME_RE =
235
+ <div class="docstring">
236
+ <div class="discussion">
237
+ <p class="note private">
238
+ <strong>This constant is part of a private API.</strong>
239
+ You should avoid using this constant if possible, as it may be removed or be changed in the future.
240
+ </p>
241
+
242
+ <p>Method names are stricter than CSV column names.</p>
243
+
244
+
245
+ </div>
246
+ </div>
247
+ <div class="tags">
248
+
249
+
250
+ </div>
251
+ </dt>
252
+ <dd><pre class="code"><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\A[_a-z][_a-z0-9]*[?!=]?\z</span><span class='regexp_end'>/</span></span></pre></dd>
253
+
174
254
  <dt id="NUMERIC-constant" class="">NUMERIC =
175
255
  <div class="docstring">
176
256
  <div class="discussion">
@@ -534,14 +614,14 @@ nil.</p>
534
614
  <pre class="lines">
535
615
 
536
616
 
537
- 143
538
- 144
539
- 145
540
- 146
541
- 147</pre>
617
+ 153
618
+ 154
619
+ 155
620
+ 156
621
+ 157</pre>
542
622
  </td>
543
623
  <td>
544
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 143</span>
624
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 153</span>
545
625
 
546
626
  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
547
627
  <span class='id identifier rubyid_matchers'>matchers</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:matchers</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_klass'>klass</span><span class='op'>|</span> <span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
@@ -608,12 +688,12 @@ nil.</p>
608
688
  <pre class="lines">
609
689
 
610
690
 
611
- 137
612
- 138
613
- 139</pre>
691
+ 147
692
+ 148
693
+ 149</pre>
614
694
  </td>
615
695
  <td>
616
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 137</span>
696
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 147</span>
617
697
 
618
698
  <span class='kw'>def</span> <span class='id identifier rubyid_ins'>ins</span>
619
699
  <span class='ivar'>@ins</span>
@@ -673,12 +753,12 @@ nil.</p>
673
753
  <pre class="lines">
674
754
 
675
755
 
676
- 140
677
- 141
678
- 142</pre>
756
+ 150
757
+ 151
758
+ 152</pre>
679
759
  </td>
680
760
  <td>
681
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 140</span>
761
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 150</span>
682
762
 
683
763
  <span class='kw'>def</span> <span class='id identifier rubyid_outs'>outs</span>
684
764
  <span class='ivar'>@outs</span>
@@ -753,15 +833,15 @@ nil.</p>
753
833
  <pre class="lines">
754
834
 
755
835
 
756
- 85
757
- 86
758
- 87</pre>
836
+ 95
837
+ 96
838
+ 97</pre>
759
839
  </td>
760
840
  <td>
761
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 85</span>
841
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 95</span>
762
842
 
763
843
  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_normalize_operator'>normalize_operator</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='rparen'>)</span>
764
- <span class='const'>EQUALS_RE</span><span class='period'>.</span><span class='id identifier rubyid_match?'>match?</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>==</span><span class='tstring_end'>&#39;</span></span> <span class='op'>:</span> <span class='id identifier rubyid_operator'>operator</span>
844
+ <span class='const'><span class='object_link'><a href="#EQUALS_RE-constant" title="CSVDecision::Matchers::EQUALS_RE (constant)">EQUALS_RE</a></span></span><span class='period'>.</span><span class='id identifier rubyid_match?'>match?</span><span class='lparen'>(</span><span class='id identifier rubyid_operator'>operator</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>==</span><span class='tstring_end'>&#39;</span></span> <span class='op'>:</span> <span class='id identifier rubyid_operator'>operator</span>
765
845
  <span class='kw'>end</span></pre>
766
846
  </td>
767
847
  </tr>
@@ -827,15 +907,15 @@ valid numeric string.</p>
827
907
  <pre class="lines">
828
908
 
829
909
 
830
- 99
831
- 100
832
- 101
833
- 102
834
- 103
835
- 104</pre>
910
+ 109
911
+ 110
912
+ 111
913
+ 112
914
+ 113
915
+ 114</pre>
836
916
  </td>
837
917
  <td>
838
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 99</span>
918
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 109</span>
839
919
 
840
920
  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_numeric'>numeric</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
841
921
  <span class='kw'>return</span> <span class='id identifier rubyid_value'>value</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Integer</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>BigDecimal</span><span class='rparen'>)</span>
@@ -944,21 +1024,21 @@ matchers.</p>
944
1024
  <pre class="lines">
945
1025
 
946
1026
 
947
- 123
948
- 124
949
- 125
950
- 126
951
- 127
952
- 128
953
- 129
954
- 130
955
- 131
956
- 132
957
1027
  133
958
- 134</pre>
1028
+ 134
1029
+ 135
1030
+ 136
1031
+ 137
1032
+ 138
1033
+ 139
1034
+ 140
1035
+ 141
1036
+ 142
1037
+ 143
1038
+ 144</pre>
959
1039
  </td>
960
1040
  <td>
961
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 123</span>
1041
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 133</span>
962
1042
 
963
1043
  <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'>columns:</span><span class='comma'>,</span> <span class='label'>matchers:</span><span class='comma'>,</span> <span class='label'>row:</span><span class='rparen'>)</span>
964
1044
  <span class='comment'># Build an array of column indexes requiring simple constant matches,
@@ -1120,15 +1200,15 @@ nil.</p>
1120
1200
  <pre class="lines">
1121
1201
 
1122
1202
 
1123
- 110
1124
- 111
1125
- 112
1126
- 113
1127
- 114
1128
- 115</pre>
1203
+ 120
1204
+ 121
1205
+ 122
1206
+ 123
1207
+ 124
1208
+ 125</pre>
1129
1209
  </td>
1130
1210
  <td>
1131
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 110</span>
1211
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 120</span>
1132
1212
 
1133
1213
  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_to_numeric'>to_numeric</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
1134
1214
  <span class='kw'>return</span> <span class='kw'>unless</span> <span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span> <span class='op'>=</span> <span class='const'>NUMERIC_RE</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span><span class='rparen'>)</span>
@@ -1231,12 +1311,12 @@ nil.</p>
1231
1311
  <pre class="lines">
1232
1312
 
1233
1313
 
1234
- 154
1235
- 155
1236
- 156</pre>
1314
+ 164
1315
+ 165
1316
+ 166</pre>
1237
1317
  </td>
1238
1318
  <td>
1239
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 154</span>
1319
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 164</span>
1240
1320
 
1241
1321
  <span class='kw'>def</span> <span class='id identifier rubyid_parse_ins'>parse_ins</span><span class='lparen'>(</span><span class='label'>columns:</span><span class='comma'>,</span> <span class='label'>row:</span><span class='rparen'>)</span>
1242
1322
  <span class='const'><span class='object_link'><a href="" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="#parse-class_method" title="CSVDecision::Matchers.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='label'>columns:</span> <span class='id identifier rubyid_columns'>columns</span><span class='comma'>,</span> <span class='label'>matchers:</span> <span class='ivar'>@ins</span><span class='comma'>,</span> <span class='label'>row:</span> <span class='id identifier rubyid_row'>row</span><span class='rparen'>)</span>
@@ -1330,12 +1410,12 @@ nil.</p>
1330
1410
  <pre class="lines">
1331
1411
 
1332
1412
 
1333
- 163
1334
- 164
1335
- 165</pre>
1413
+ 173
1414
+ 174
1415
+ 175</pre>
1336
1416
  </td>
1337
1417
  <td>
1338
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 163</span>
1418
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 173</span>
1339
1419
 
1340
1420
  <span class='kw'>def</span> <span class='id identifier rubyid_parse_outs'>parse_outs</span><span class='lparen'>(</span><span class='label'>columns:</span><span class='comma'>,</span> <span class='label'>row:</span><span class='rparen'>)</span>
1341
1421
  <span class='const'><span class='object_link'><a href="" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="#parse-class_method" title="CSVDecision::Matchers.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='label'>columns:</span> <span class='id identifier rubyid_columns'>columns</span><span class='comma'>,</span> <span class='label'>matchers:</span> <span class='ivar'>@outs</span><span class='comma'>,</span> <span class='label'>row:</span> <span class='id identifier rubyid_row'>row</span><span class='rparen'>)</span>
@@ -1350,7 +1430,7 @@ nil.</p>
1350
1430
  </div>
1351
1431
 
1352
1432
  <div id="footer">
1353
- Generated on Sun Jan 28 11:58:38 2018 by
1433
+ Generated on Sun Jan 28 14:41:48 2018 by
1354
1434
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1355
1435
  0.9.12 (ruby-2.4.0).
1356
1436
  </div>
@@ -474,7 +474,7 @@ some type of function.</p>
474
474
  </div>
475
475
 
476
476
  <div id="footer">
477
- Generated on Sun Jan 28 11:58:39 2018 by
477
+ Generated on Sun Jan 28 14:41:49 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 Sun Jan 28 11:58:39 2018 by
504
+ Generated on Sun Jan 28 14:41:50 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 Sun Jan 28 11:58:39 2018 by
496
+ Generated on Sun Jan 28 14:41:49 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>
@@ -267,10 +267,10 @@
267
267
  <pre class="lines">
268
268
 
269
269
 
270
- 169</pre>
270
+ 179</pre>
271
271
  </td>
272
272
  <td>
273
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 169</span>
273
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 179</span>
274
274
 
275
275
  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid__options'>_options</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span><span class='semicolon'>;</span> <span class='kw'>end</span></pre>
276
276
  </td>
@@ -333,12 +333,12 @@
333
333
  <pre class="lines">
334
334
 
335
335
 
336
- 191
337
- 192
338
- 193</pre>
336
+ 201
337
+ 202
338
+ 203</pre>
339
339
  </td>
340
340
  <td>
341
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 191</span>
341
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 201</span>
342
342
 
343
343
  <span class='kw'>def</span> <span class='id identifier rubyid_ins?'>ins?</span>
344
344
  <span class='kw'>true</span>
@@ -418,10 +418,10 @@ some type of function.</p>
418
418
  <pre class="lines">
419
419
 
420
420
 
421
- 177</pre>
421
+ 187</pre>
422
422
  </td>
423
423
  <td>
424
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 177</span>
424
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 187</span>
425
425
 
426
426
  <span class='kw'>def</span> <span class='id identifier rubyid_matches?'>matches?</span><span class='lparen'>(</span><span class='id identifier rubyid_cell'>cell</span><span class='rparen'>)</span><span class='semicolon'>;</span> <span class='kw'>end</span></pre>
427
427
  </td>
@@ -477,12 +477,12 @@ some type of function.</p>
477
477
  <pre class="lines">
478
478
 
479
479
 
480
- 183
481
- 184
482
- 185</pre>
480
+ 193
481
+ 194
482
+ 195</pre>
483
483
  </td>
484
484
  <td>
485
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 183</span>
485
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers.rb', line 193</span>
486
486
 
487
487
  <span class='kw'>def</span> <span class='id identifier rubyid_outs?'>outs?</span>
488
488
  <span class='kw'>false</span>
@@ -497,7 +497,7 @@ some type of function.</p>
497
497
  </div>
498
498
 
499
499
  <div id="footer">
500
- Generated on Sun Jan 28 11:58:39 2018 by
500
+ Generated on Sun Jan 28 14:41:49 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 Sun Jan 28 11:58:39 2018 by
414
+ Generated on Sun Jan 28 14:41:49 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 Sun Jan 28 11:58:39 2018 by
484
+ Generated on Sun Jan 28 14:41:49 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 Sun Jan 28 11:58:39 2018 by
697
+ Generated on Sun Jan 28 14:41:49 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 Sun Jan 28 11:58:39 2018 by
372
+ Generated on Sun Jan 28 14:41:49 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>
@@ -108,7 +108,8 @@
108
108
  You should avoid using this class if possible, as it may be removed or be changed in the future.
109
109
  </p>
110
110
 
111
- <p>Match cell against a symbolic expression - e.g., :column, &gt; :column</p>
111
+ <p>Match cell against a symbolic expression - e.g., :column, &gt; :column. Can
112
+ also call a Ruby method pn the column value - e.g, .blank? or !.blank?</p>
112
113
 
113
114
 
114
115
  </div>
@@ -290,27 +291,37 @@ some type of function.</p>
290
291
  <pre class="lines">
291
292
 
292
293
 
293
- 69
294
- 70
295
- 71
296
- 72
297
- 73
298
- 74
299
- 75
300
- 76
301
- 77</pre>
294
+ 108
295
+ 109
296
+ 110
297
+ 111
298
+ 112
299
+ 113
300
+ 114
301
+ 115
302
+ 116
303
+ 117
304
+ 118
305
+ 119
306
+ 120
307
+ 121</pre>
302
308
  </td>
303
309
  <td>
304
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers/symbol.rb', line 69</span>
310
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers/symbol.rb', line 108</span>
305
311
 
306
312
  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_matches?'>matches?</span><span class='lparen'>(</span><span class='id identifier rubyid_cell'>cell</span><span class='rparen'>)</span>
307
- <span class='id identifier rubyid_match'>match</span> <span class='op'>=</span> <span class='const'>SYMBOL_COMPARE_RE</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_cell'>cell</span><span class='rparen'>)</span>
308
- <span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>unless</span> <span class='id identifier rubyid_match'>match</span>
313
+ <span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>unless</span> <span class='lparen'>(</span><span class='id identifier rubyid_match'>match</span> <span class='op'>=</span> <span class='const'>SYMBOL_COMPARE_RE</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_cell'>cell</span><span class='rparen'>)</span><span class='rparen'>)</span>
309
314
 
310
315
  <span class='id identifier rubyid_comparator'>comparator</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>comparator</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>=</span><span class='tstring_end'>&#39;</span></span>
311
316
  <span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>name</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
312
-
313
- <span class='id identifier rubyid_comparison'>comparison</span><span class='lparen'>(</span><span class='label'>comparator:</span> <span class='id identifier rubyid_comparator'>comparator</span><span class='comma'>,</span> <span class='label'>name:</span> <span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
317
+ <span class='kw'>if</span> <span class='id identifier rubyid_match'>match</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>type</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>:</span><span class='tstring_end'>&#39;</span></span>
318
+ <span class='id identifier rubyid_comparison'>comparison</span><span class='lparen'>(</span><span class='label'>comparator:</span> <span class='id identifier rubyid_comparator'>comparator</span><span class='comma'>,</span> <span class='label'>name:</span> <span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
319
+
320
+ <span class='comment'># Method call - e.g, .blank? or !.present?
321
+ </span> <span class='comment'># Can also take the forms: := .blank? or !=.present?
322
+ </span> <span class='kw'>else</span>
323
+ <span class='id identifier rubyid_method_call'>method_call</span><span class='lparen'>(</span><span class='label'>comparator:</span> <span class='id identifier rubyid_comparator'>comparator</span><span class='comma'>,</span> <span class='label'>name:</span> <span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
324
+ <span class='kw'>end</span>
314
325
  <span class='kw'>end</span></pre>
315
326
  </td>
316
327
  </tr>
@@ -395,12 +406,12 @@ some type of function.</p>
395
406
  <pre class="lines">
396
407
 
397
408
 
398
- 81
399
- 82
400
- 83</pre>
409
+ 125
410
+ 126
411
+ 127</pre>
401
412
  </td>
402
413
  <td>
403
- <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers/symbol.rb', line 81</span>
414
+ <pre class="code"><span class="info file"># File 'lib/csv_decision/matchers/symbol.rb', line 125</span>
404
415
 
405
416
  <span class='kw'>def</span> <span class='id identifier rubyid_matches?'>matches?</span><span class='lparen'>(</span><span class='id identifier rubyid_cell'>cell</span><span class='rparen'>)</span>
406
417
  <span class='const'><span class='object_link'><a href="" title="CSVDecision::Matchers::Symbol (class)">Symbol</a></span></span><span class='period'>.</span><span class='id identifier rubyid_matches?'><span class='object_link'><a href="#matches%3F-class_method" title="CSVDecision::Matchers::Symbol.matches? (method)">matches?</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_cell'>cell</span><span class='rparen'>)</span>
@@ -415,7 +426,7 @@ some type of function.</p>
415
426
  </div>
416
427
 
417
428
  <div id="footer">
418
- Generated on Sun Jan 28 11:58:39 2018 by
429
+ Generated on Sun Jan 28 14:41:49 2018 by
419
430
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
420
431
  0.9.12 (ruby-2.4.0).
421
432
  </div>
@@ -433,7 +433,7 @@ set.</p>
433
433
  </div>
434
434
 
435
435
  <div id="footer">
436
- Generated on Sun Jan 28 11:58:38 2018 by
436
+ Generated on Sun Jan 28 14:41:48 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 Sun Jan 28 11:58:38 2018 by
275
+ Generated on Sun Jan 28 14:41:48 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>
@@ -1121,7 +1121,7 @@ result, along with the partial result required to evaluate functions.</p>
1121
1121
  </div>
1122
1122
 
1123
1123
  <div id="footer">
1124
- Generated on Sun Jan 28 11:58:38 2018 by
1124
+ Generated on Sun Jan 28 14:41:49 2018 by
1125
1125
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1126
1126
  0.9.12 (ruby-2.4.0).
1127
1127
  </div>
@@ -856,7 +856,7 @@ non-string constant.</p>
856
856
  </div>
857
857
 
858
858
  <div id="footer">
859
- Generated on Sun Jan 28 11:58:39 2018 by
859
+ Generated on Sun Jan 28 14:41:49 2018 by
860
860
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
861
861
  0.9.12 (ruby-2.4.0).
862
862
  </div>
@@ -1378,7 +1378,7 @@ and last row index given.</p>
1378
1378
  </div>
1379
1379
 
1380
1380
  <div id="footer">
1381
- Generated on Sun Jan 28 11:58:38 2018 by
1381
+ Generated on Sun Jan 28 14:41:48 2018 by
1382
1382
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1383
1383
  0.9.12 (ruby-2.4.0).
1384
1384
  </div>
@@ -133,7 +133,7 @@
133
133
  </div>
134
134
 
135
135
  <div id="footer">
136
- Generated on Sun Jan 28 11:58:38 2018 by
136
+ Generated on Sun Jan 28 14:41:48 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 Sun Jan 28 11:58:38 2018 by
415
+ Generated on Sun Jan 28 14:41:48 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 Sun Jan 28 11:58:36 2018 by
443
+ Generated on Sun Jan 28 14:41:46 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
@@ -261,8 +261,12 @@ the input hash. The expression, <code>== :node</code> should be read as
261
261
  <p><code>ruby data = &lt;&lt;~DATA in :parent, out :top?
262
262
  :node, yes , no DATA </code> These comparison
263
263
  operators are also supported: <code>!=</code>, <code>&gt;</code>,
264
- <code>&gt;=</code>, <code>&lt;</code>, <code>&lt;=</code>. For more simple
265
- examples see <code>spec/csv_decision/examples_spec.rb</code>.</p>
264
+ <code>&gt;=</code>, <code>&lt;</code>, <code>&lt;=</code>. In addition, you
265
+ can also apply a Ruby 0-arity method - e.g., <code>.present?</code> or
266
+ <code>.nil?</code>. Negation is also supported - e.g., <code>!.nil?</code>.</p>
267
+
268
+ <p>For more simple examples see
269
+ <code>spec/csv_decision/examples_spec.rb</code>.</p>
266
270
 
267
271
  <h4 id="label-Input+guard+conditions">Input <code>guard</code> conditions</h4>
268
272
 
@@ -385,7 +389,7 @@ href="./LICENSE">LICENSE</a> document for more information.</p>
385
389
  </div></div>
386
390
 
387
391
  <div id="footer">
388
- Generated on Sun Jan 28 11:58:37 2018 by
392
+ Generated on Sun Jan 28 14:41:48 2018 by
389
393
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
390
394
  0.9.12 (ruby-2.4.0).
391
395
  </div>
data/doc/index.html CHANGED
@@ -261,8 +261,12 @@ the input hash. The expression, <code>== :node</code> should be read as
261
261
  <p><code>ruby data = &lt;&lt;~DATA in :parent, out :top?
262
262
  :node, yes , no DATA </code> These comparison
263
263
  operators are also supported: <code>!=</code>, <code>&gt;</code>,
264
- <code>&gt;=</code>, <code>&lt;</code>, <code>&lt;=</code>. For more simple
265
- examples see <code>spec/csv_decision/examples_spec.rb</code>.</p>
264
+ <code>&gt;=</code>, <code>&lt;</code>, <code>&lt;=</code>. In addition, you
265
+ can also apply a Ruby 0-arity method - e.g., <code>.present?</code> or
266
+ <code>.nil?</code>. Negation is also supported - e.g., <code>!.nil?</code>.</p>
267
+
268
+ <p>For more simple examples see
269
+ <code>spec/csv_decision/examples_spec.rb</code>.</p>
266
270
 
267
271
  <h4 id="label-Input+guard+conditions">Input <code>guard</code> conditions</h4>
268
272
 
@@ -385,7 +389,7 @@ href="./LICENSE">LICENSE</a> document for more information.</p>
385
389
  </div></div>
386
390
 
387
391
  <div id="footer">
388
- Generated on Sun Jan 28 11:58:37 2018 by
392
+ Generated on Sun Jan 28 14:41:47 2018 by
389
393
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
390
394
  0.9.12 (ruby-2.4.0).
391
395
  </div>
@@ -100,7 +100,7 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Sun Jan 28 11:58:37 2018 by
103
+ Generated on Sun Jan 28 14:41:48 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>
@@ -72,11 +72,21 @@ module CSVDecision
72
72
  Regexp.new("\\A(?:#{value})\\z").freeze
73
73
  end
74
74
 
75
- # Cell constants and functions specified by prefixing the value with one of these 3 symbols.
75
+ # Symbols used for inequality
76
+ INEQUALITY = '!=|!'
77
+
78
+ # Match string for inequality
79
+ INEQUALITY_RE = regexp(INEQUALITY)
80
+
81
+ # Equality, cell constants and functions specified by prefixing the value with
82
+ # one of these 3 symbols.
76
83
  EQUALS = '==|:=|='
77
84
 
85
+ # Match string for equality
78
86
  EQUALS_RE = regexp(EQUALS)
79
- private_constant :EQUALS_RE
87
+
88
+ # Method names are stricter than CSV column names.
89
+ METHOD_NAME_RE = /\A[_a-z][_a-z0-9]*[?!=]?\z/
80
90
 
81
91
  # Normalize the operators which are a variation on equals/assignment.
82
92
  #
@@ -8,11 +8,16 @@ module CSVDecision
8
8
  # Recognise expressions in table data cells.
9
9
  # @api private
10
10
  class Matchers
11
- # Match cell against a symbolic expression - e.g., :column, > :column
11
+ # Match cell against a symbolic expression - e.g., :column, > :column.
12
+ # Can also call a Ruby method pn the column value - e.g, .blank? or !.blank?
12
13
  class Symbol < Matcher
13
- # Column symbol comparison - e.g., > :column or != :column
14
+ SYMBOL_COMPARATORS = "#{INEQUALITY}|>=|<=|<|>|#{EQUALS}"
15
+ private_constant :SYMBOL_COMPARATORS
16
+
17
+ # Column symbol comparison - e.g., > :column or != :column.
18
+ # Can also be a method call - e.g., .present? or .blank?
14
19
  SYMBOL_COMPARE =
15
- "(?<comparator>!=|>=|<=|<|>|#{Matchers::EQUALS})?\\s*:(?<name>#{Header::COLUMN_NAME})"
20
+ "(?<comparator>#{SYMBOL_COMPARATORS})?\\s*(?<type>[.:])(?<name>#{Header::COLUMN_NAME})"
16
21
  private_constant :SYMBOL_COMPARE
17
22
 
18
23
  # Symbol comparision regular expression.
@@ -33,6 +38,20 @@ module CSVDecision
33
38
  end
34
39
  private_class_method :compare_proc
35
40
 
41
+ def self.value_method(value, method)
42
+ value.respond_to?(method) && value.send(method)
43
+ end
44
+ private_class_method :value_method
45
+
46
+ def self.method_proc(negate:)
47
+ if negate
48
+ proc { |symbol, value| !value_method(value, symbol) }
49
+ else
50
+ proc { |symbol, value| value_method(value, symbol) }
51
+ end
52
+ end
53
+ private_class_method :method_proc
54
+
36
55
  COMPARE = {
37
56
  # Equality and inequality - create a lambda proc by calling with the actual column name
38
57
  # symbol.
@@ -40,12 +59,17 @@ module CSVDecision
40
59
  '=' => ->(symbol) { EQUALITY[':='].curry[symbol].freeze },
41
60
  '==' => ->(symbol) { EQUALITY[':='].curry[symbol].freeze },
42
61
  '!=' => ->(symbol) { EQUALITY['!='].curry[symbol].freeze },
62
+ '!' => ->(symbol) { EQUALITY['!='].curry[symbol].freeze },
43
63
 
44
64
  # Comparisons - create a lambda proc by calling with the actual column name symbol.
45
65
  '>' => ->(symbol) { compare_proc(:'>').curry[symbol].freeze },
46
66
  '>=' => ->(symbol) { compare_proc(:'>=').curry[symbol].freeze },
47
67
  '<' => ->(symbol) { compare_proc(:'<').curry[symbol].freeze },
48
- '<=' => ->(symbol) { compare_proc(:'<=').curry[symbol].freeze }
68
+ '<=' => ->(symbol) { compare_proc(:'<=').curry[symbol].freeze },
69
+
70
+ # 0-arity Ruby method calls applied to an input column value.
71
+ '.' => ->(symbol) { method_proc(negate: false).curry[symbol].freeze },
72
+ '!.' => ->(symbol) { method_proc(negate: true).curry[symbol].freeze }
49
73
  }.freeze
50
74
  private_constant :COMPARE
51
75
 
@@ -57,23 +81,48 @@ module CSVDecision
57
81
  end
58
82
  private_class_method :compare?
59
83
 
60
- # E.g., > :col, we get comparator: >, args: col
84
+ # E.g., > :col, we get comparator: >, name: col
61
85
  def self.comparison(comparator:, name:)
62
86
  function = COMPARE[comparator]
63
87
  Matchers::Proc.new(type: :symbol, function: function[name], symbols: name)
64
88
  end
65
89
  private_class_method :comparison
66
90
 
91
+ # E.g., !.nil?, we get comparator: !, name: nil?
92
+ def self.method_call(comparator:, name:)
93
+ equality = EQUALS_RE.match?(comparator)
94
+ inequality = !equality && INEQUALITY_RE.match?(comparator)
95
+ return false unless equality || inequality
96
+
97
+ method_function(name: name, negate: inequality)
98
+ end
99
+ private_class_method :method_call
100
+
101
+ # E.g., !.nil?, we get comparator: !, name: nil?
102
+ def self.method_function(name:, negate:)
103
+ # Allowed Ruby method names are a bit stricter than allowed decision table column names.
104
+ return false unless METHOD_NAME_RE.match?(name)
105
+
106
+ function = COMPARE[negate ? '!.' : '.']
107
+ Matchers::Proc.new(type: :proc, function: function[name])
108
+ end
109
+ private_class_method :method_function
110
+
67
111
  # @param (see Matchers::Matcher#matches?)
68
112
  # @return (see Matchers::Matcher#matches?)
69
113
  def self.matches?(cell)
70
- match = SYMBOL_COMPARE_RE.match(cell)
71
- return false unless match
114
+ return false unless (match = SYMBOL_COMPARE_RE.match(cell))
72
115
 
73
116
  comparator = match['comparator'] || '='
74
117
  name = match['name'].to_sym
118
+ if match['type'] == ':'
119
+ comparison(comparator: comparator, name: name)
75
120
 
76
- comparison(comparator: comparator, name: name)
121
+ # Method call - e.g, .blank? or !.present?
122
+ # Can also take the forms: := .blank? or !=.present?
123
+ else
124
+ method_call(comparator: comparator, name: name)
125
+ end
77
126
  end
78
127
 
79
128
  # @param (see Matcher#matches?)
@@ -197,4 +197,21 @@ context 'simple examples' do
197
197
  expect(table.decide(ISIN: '123456789', country: 'GB', class: 'public')).to eq({})
198
198
  expect(table.decide(ISIN: '123456789012', country: 'GB', class: 'private')).to eq(PAID: '123456789012', len: 12)
199
199
  end
200
+
201
+ it 'recognises in column method call conditions' do
202
+ data = <<~DATA
203
+ set/nil? :country, in :CUSIP, in :ISIN, set: class, out :PAID, out: len, if:
204
+ US, , , :class.upcase,
205
+ US, .present?, , != PRIVATE, :CUSIP, :PAID.length, :len == 9
206
+ !=US, , .present?, != PRIVATE, :ISIN, :PAID.length, :len == 12
207
+ US, =.present?, , PRIVATE, :CUSIP, :PAID.length,
208
+ !=US, , !.blank?, PRIVATE, :ISIN, :PAID.length,
209
+ DATA
210
+
211
+ table = CSVDecision.parse(data)
212
+ expect(table.decide(CUSIP: '1234567890', class: 'Private')).to eq(PAID: '1234567890', len: 10)
213
+ expect(table.decide(CUSIP: '123456789', class: 'Public')).to eq(PAID: '123456789', len: 9)
214
+ expect(table.decide(ISIN: '123456789', country: 'GB', class: 'public')).to eq({})
215
+ expect(table.decide(ISIN: '123456789012', country: 'GB', class: 'private')).to eq(PAID: '123456789012', len: 12)
216
+ end
200
217
  end
@@ -266,9 +266,9 @@ describe CSVDecision::Table do
266
266
  { example: 'uses != :parent, drops :parent input column',
267
267
  options: {},
268
268
  data: <<~DATA
269
- in :node, out :top?
270
- != :parent, no
271
- , yes
269
+ in :node, out :top?
270
+ !:parent, no
271
+ , yes
272
272
  DATA
273
273
  },
274
274
  { example: 'uses != :parent and == :parent',
@@ -532,7 +532,7 @@ describe CSVDecision::Table do
532
532
 
533
533
  context 'uses multi-column index to make correct decisions' do
534
534
  examples = [
535
- { example: 'evaluates multi-column index CSV string',
535
+ { example: 'evaluates multi-column index CSV string with guard',
536
536
  options: { first_match: true },
537
537
  data: <<~DATA
538
538
  guard:, in :type, IN :input, OUT :output
@@ -546,6 +546,34 @@ describe CSVDecision::Table do
546
546
  :number.blank?, string, one, :=nil
547
547
  DATA
548
548
  },
549
+ { example: 'evaluates multi-column index CSV string with symbol conditions',
550
+ options: { first_match: true },
551
+ data: <<~DATA
552
+ in: number, in: string, in :type, IN :input, OUT :output
553
+ .present?, , integer, none, :=0
554
+ .blank?, , integer, none, :=nil
555
+ .present?, , integer, one, :=1
556
+ .blank?, , integer, one, :=nil
557
+ , .present?, string, none, 0
558
+ .blank?, , string, none, :=nil
559
+ , .present?, string, one, 1
560
+ .blank?, , string, one, :=nil
561
+ DATA
562
+ },
563
+ { example: 'evaluates multi-column index CSV string with negated symbol conditions',
564
+ options: { first_match: true },
565
+ data: <<~DATA
566
+ in: number, in: string, in :type, IN :input, OUT :output
567
+ !.blank?, , integer, none, :=0
568
+ != .present?, , integer, none, :=nil
569
+ =.present?, , integer, one, :=1
570
+ ==.blank?, , integer, one, :=nil
571
+ , .present?, string, none, 0
572
+ .blank?, , string, none, :=nil
573
+ , !.blank?, string, one, 1
574
+ .blank?, , string, one, :=nil
575
+ DATA
576
+ },
549
577
  { example: 'evaluates multi-column index CSV file',
550
578
  options: { first_match: true },
551
579
  data: Pathname(File.join(SPEC_DATA_VALID, 'multi_column_index.csv'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_decision
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Vickers