Skip to content

Commit

Permalink
Update documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpvickers committed Dec 30, 2017
1 parent 57cfa16 commit bba496c
Show file tree
Hide file tree
Showing 36 changed files with 689 additions and 974 deletions.
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,26 @@ These comparison operators are also supported: `!=`, `>`, `>=`, `<`, `<=`.
For more simple examples see `spec/csv_decision/examples_spec.rb`.

### Column guard conditions
Sometimes it's more convenient to write guard conditions in a single column specialized for that purpose.

Sometimes it's more convenient to write guard conditions in a single column specialized for that purpose.
For example:
```ruby
data = <<~DATA
in :node, in :parent, out :top?
, == :node, yes
, , no
DATA

table = CSVDecision.parse(data)
table.decide(node: 0, parent: 0) # returns top?: 'yes'
table.decide(node: 1, parent: 0) # returns top?: 'no'
```

```ruby
data = <<~DATA
in :country, guard:, out :ID, out :ID_type, out :len
US, :CUSIP.present?, :CUSIP, CUSIP, :ID.length
GB, :SEDOL.present?, :SEDOL, SEDOL, :ID.length
, :ISIN.present?, :ISIN, ISIN, :ID.length
, :SEDOL.present?, :SEDOL, SEDOL, :ID.length
, :CUSIP.present?, :CUSIP, CUSIP, :ID.length
, , := nil, := nil, := nil
DATA

table = CSVDecision.parse(data)
table.decide(country: 'US', CUSIP: '123456789') #=> { ID: '123456789', ID_type: 'CUSIP', len: 9 }
table.decide(country: 'EU', CUSIP: '123456789', ISIN:'123456789012')
#=> { ID: '123456789012', ID_type: 'ISIN', len: 12 }
```
Guard columns may be anonymous, and must contain non-constant expressions.

### Testing

Expand Down
10 changes: 5 additions & 5 deletions csv_decision.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Gem::Specification.new do |spec|
spec.email = ['brett@phillips-vickers.com']
spec.description = 'CSV based Ruby decision tables.'
spec.summary = <<-DESC
CSV Decision implements CSV file based Ruby decision tables. It accepts decision tables implemented as a
which can then be used to execute complex conditional logic against an input hash,
producing a decision as an output hash.
CSV Decision implements CSV based Ruby decision tables. It parses and loads
decision table files which can then be used to execute complex conditional
logic against an input hash, producing a decision as an output hash.
DESC
spec.homepage = 'https://github.com/bpvickers/csv_decision.git'
spec.license = 'MIT'
Expand All @@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.3.0'

spec.add_dependency 'activesupport', '~> 5.1'
spec.add_dependency 'ice_nine', '~> 0.11'
spec.add_dependency 'values', '~> 1.8'
spec.add_dependency 'ice_nine', '~> 0.11'
spec.add_dependency 'values', '~> 1.8'

spec.add_development_dependency 'benchmark-ips', '~> 2.7'
spec.add_development_dependency 'benchmark-memory', '~> 0.1'
Expand Down
47 changes: 9 additions & 38 deletions doc/CSVDecision.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,6 @@ <h2>Overview</h2><div class="docstring">

</p>

<h2>Constant Summary</h2>
<dl class="constants">

<dt id="DEFAULT_MATCHERS-constant" class="">DEFAULT_MATCHERS =
<div class="docstring">
<div class="discussion">

<p>Specialized cell value matchers beyond simple string compares. By default
all these matchers are tried in the specified order on all input data
cells.</p>


</div>
</div>
<div class="tags">


</div>
</dt>
<dd><pre class="code"><span class='lbracket'>[</span>
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Range.html" title="CSVDecision::Matchers::Range (class)">Range</a></span></span><span class='comma'>,</span>
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Numeric.html" title="CSVDecision::Matchers::Numeric (class)">Numeric</a></span></span><span class='comma'>,</span>
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Pattern.html" title="CSVDecision::Matchers::Pattern (class)">Pattern</a></span></span><span class='comma'>,</span>
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Constant.html" title="CSVDecision::Matchers::Constant (class)">Constant</a></span></span><span class='comma'>,</span>
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Symbol.html" title="CSVDecision::Matchers::Symbol (class)">Symbol</a></span></span><span class='comma'>,</span>
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Guard.html" title="CSVDecision::Matchers::Guard (class)">Guard</a></span></span>
<span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>

</dl>




Expand Down Expand Up @@ -302,7 +272,7 @@ <h3 class="signature first" id="load-class_method">

&mdash;
<div class='inline'>
<p>Supplied options hash for table creation.</p>
<p>Options hash used for table creation.</p>
</div>

</li>
Expand Down Expand Up @@ -391,7 +361,8 @@ <h3 class="signature " id="parse-class_method">
</div></p>

<pre class="example code"><code>If you have cloned the gem&#39;s git repo, then you can run:
table = CSVDecision.parse(Pathname(&#39;spec/data/valid/simple_example.csv&#39;)) #=&gt; CSVDecision::Table
table = CSVDecision.parse(Pathname(&#39;spec/data/valid/simple_example.csv&#39;))
#=&gt; CSVDecision::Table
table.decide(topic: &#39;finance&#39;, region: &#39;Europe&#39;) #=&gt; team_member: &#39;Donald&#39;</code></pre>

</div>
Expand Down Expand Up @@ -450,7 +421,7 @@ <h3 class="signature " id="parse-class_method">
</span>

&mdash; <div class='inline'>
<p>Stop scanning after find the first row match.</p>
<p>Stop scanning after finding the first row match.</p>
</div>

</li>
Expand Down Expand Up @@ -556,12 +527,12 @@ <h3 class="signature " id="parse-class_method">
<pre class="lines">


44
45
46</pre>
46
47
48</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/csv_decision/parse.rb', line 44</span>
<pre class="code"><span class="info file"># File 'lib/csv_decision/parse.rb', line 46</span>

<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='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='const'><span class='object_link'><a href="CSVDecision/Parse.html" title="CSVDecision::Parse (module)">Parse</a></span></span><span class='period'>.</span><span class='id identifier rubyid_table'><span class='object_link'><a href="CSVDecision/Parse.html#table-class_method" title="CSVDecision::Parse.table (method)">table</a></span></span><span class='lparen'>(</span><span class='label'>data:</span> <span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='const'><span class='object_link'><a href="CSVDecision/Options.html" title="CSVDecision::Options (module)">Options</a></span></span><span class='period'>.</span><span class='id identifier rubyid_normalize'><span class='object_link'><a href="CSVDecision/Options.html#normalize-class_method" title="CSVDecision::Options.normalize (method)">normalize</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span><span class='rparen'>)</span>
Expand Down Expand Up @@ -635,7 +606,7 @@ <h3 class="signature " id="root-class_method">
</div>

<div id="footer">
Generated on Fri Dec 29 10:35:53 2017 by
Generated on Sat Dec 30 13:04:04 2017 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.12 (ruby-2.3.0).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/CSVDecision/CellValidationError.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ <h2>Overview</h2><div class="docstring">
</div>

<div id="footer">
Generated on Fri Dec 29 10:35:54 2017 by
Generated on Sat Dec 30 13:04:05 2017 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.12 (ruby-2.3.0).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/CSVDecision/Columns.html
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ <h3 class="signature " id="outs-instance_method">
</div>

<div id="footer">
Generated on Fri Dec 29 10:35:54 2017 by
Generated on Sat Dec 30 13:04:05 2017 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.12 (ruby-2.3.0).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/CSVDecision/Columns/Dictionary.html
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ <h3 class="signature " id="outs-instance_method">
</div>

<div id="footer">
Generated on Fri Dec 29 10:35:54 2017 by
Generated on Sat Dec 30 13:04:05 2017 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.12 (ruby-2.3.0).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/CSVDecision/Columns/Entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ <h3 class="signature first" id="ins?-instance_method">
</div>

<div id="footer">
Generated on Fri Dec 29 10:35:54 2017 by
Generated on Sat Dec 30 13:04:05 2017 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.12 (ruby-2.3.0).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/CSVDecision/Data.html
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ <h3 class="signature " id="to_array-class_method">
</div>

<div id="footer">
Generated on Fri Dec 29 10:35:53 2017 by
Generated on Sat Dec 30 13:04:04 2017 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.12 (ruby-2.3.0).
</div>
Expand Down
170 changes: 157 additions & 13 deletions doc/CSVDecision/Decide.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ <h2>
<p>Main method for making decisions.</p>
</div></span>

</li>


<li class="public ">
<span class="summary_signature">

<a href="#matches%3F-class_method" title="matches? (class method)">.<strong>matches?</strong>(row:, input:, scan_row:) &#x21d2; Boolean </a>



</span>






<span class="private note title">private</span>


<span class="summary_desc"><div class='inline'>
<p>Match the table row against the input hash.</p>
</div></span>

</li>


Expand Down Expand Up @@ -248,20 +272,20 @@ <h3 class="signature first" id="decide-class_method">
<pre class="lines">


18
19
20
21
22
23
24
25
26
27
28</pre>
33
34
35
36
37
38
39
40
41
42
43</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/csv_decision/decide.rb', line 18</span>
<pre class="code"><span class="info file"># File 'lib/csv_decision/decide.rb', line 33</span>

<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_decide'>decide</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>
<span class='comment'># Parse and transform the hash supplied as input
Expand All @@ -277,14 +301,134 @@ <h3 class="signature first" id="decide-class_method">
</td>
</tr>
</table>
</div>

<div class="method_details ">
<h3 class="signature " id="matches?-class_method">

.<strong>matches?</strong>(row:, input:, scan_row:) &#x21d2; <tt>Boolean</tt>





</h3><div class="docstring">
<div class="discussion">
<p class="note private">
<strong>This method is part of a private API.</strong>
You should avoid using this method if possible, as it may be removed or be changed in the future.
</p>

<p>Match the table row against the input hash.</p>


</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">

<li>

<span class='name'>row</span>


<span class='type'>(<tt>Array</tt>)</span>



&mdash;
<div class='inline'>
<p>Table row.</p>
</div>

</li>

<li>

<span class='name'>input</span>


<span class='type'>(<tt>Hash{Symbol=&gt;Object}</tt>)</span>



&mdash;
<div class='inline'>
<p>Input hash data structure.</p>
</div>

</li>

<li>

<span class='name'>scan_row</span>


<span class='type'>(<tt><span class='object_link'><a href="ScanRow.html" title="CSVDecision::ScanRow (class)">ScanRow</a></span></tt>)</span>



</li>

</ul>

<p class="tag_title">Returns:</p>
<ul class="return">

<li>


<span class='type'>(<tt>Boolean</tt>)</span>



&mdash;
<div class='inline'>
<p>Returns true if a match, false otherwise.</p>
</div>

</li>

</ul>

</div><table class="source_code">
<tr>
<td>
<pre class="lines">


17
18
19
20
21
22
23
24</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/csv_decision/decide.rb', line 17</span>

<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='label'>row:</span><span class='comma'>,</span> <span class='label'>input:</span><span class='comma'>,</span> <span class='label'>scan_row:</span><span class='rparen'>)</span>
<span class='id identifier rubyid_match'>match</span> <span class='op'>=</span> <span class='id identifier rubyid_scan_row'>scan_row</span><span class='period'>.</span><span class='id identifier rubyid_match_constants?'>match_constants?</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'>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>
<span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>unless</span> <span class='id identifier rubyid_match'>match</span>

<span class='kw'>return</span> <span class='kw'>true</span> <span class='kw'>if</span> <span class='id identifier rubyid_scan_row'>scan_row</span><span class='period'>.</span><span class='id identifier rubyid_procs'>procs</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>

<span class='id identifier rubyid_scan_row'>scan_row</span><span class='period'>.</span><span class='id identifier rubyid_match_procs?'>match_procs?</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'>input:</span> <span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>

</div>

</div>

<div id="footer">
Generated on Fri Dec 29 10:35:53 2017 by
Generated on Sat Dec 30 13:04:04 2017 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.12 (ruby-2.3.0).
</div>
Expand Down
Loading

0 comments on commit bba496c

Please sign in to comment.