csv_decision2 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/README.md +16 -16
  4. data/benchmarks/rufus_decision.rb +5 -7
  5. data/csv_decision2.gemspec +2 -2
  6. data/doc/CSVDecision/CellValidationError.html +117 -110
  7. data/doc/CSVDecision/Columns/Default.html +537 -508
  8. data/doc/CSVDecision/Columns/Dictionary.html +729 -686
  9. data/doc/CSVDecision/Columns/Entry.html +457 -433
  10. data/doc/CSVDecision/Columns.html +1134 -1051
  11. data/doc/CSVDecision/Constant.html +205 -191
  12. data/doc/CSVDecision/Data.html +423 -398
  13. data/doc/CSVDecision/Decide.html +236 -225
  14. data/doc/CSVDecision/Decision.html +872 -825
  15. data/doc/CSVDecision/Defaults.html +243 -230
  16. data/doc/CSVDecision/Dictionary/Entry.html +1026 -964
  17. data/doc/CSVDecision/Dictionary.html +377 -355
  18. data/doc/CSVDecision/Error.html +116 -105
  19. data/doc/CSVDecision/FileError.html +117 -110
  20. data/doc/CSVDecision/Function.html +181 -168
  21. data/doc/CSVDecision/Guard.html +200 -185
  22. data/doc/CSVDecision/Header.html +557 -523
  23. data/doc/CSVDecision/Index.html +652 -617
  24. data/doc/CSVDecision/Input.html +329 -312
  25. data/doc/CSVDecision/Load.html +232 -220
  26. data/doc/CSVDecision/Matchers/Constant.html +432 -399
  27. data/doc/CSVDecision/Matchers/Function.html +451 -415
  28. data/doc/CSVDecision/Matchers/Guard.html +459 -424
  29. data/doc/CSVDecision/Matchers/Matcher.html +470 -426
  30. data/doc/CSVDecision/Matchers/Numeric.html +375 -346
  31. data/doc/CSVDecision/Matchers/Pattern.html +429 -396
  32. data/doc/CSVDecision/Matchers/Proc.html +617 -575
  33. data/doc/CSVDecision/Matchers/Range.html +331 -302
  34. data/doc/CSVDecision/Matchers/Symbol.html +386 -353
  35. data/doc/CSVDecision/Matchers.html +1509 -1393
  36. data/doc/CSVDecision/Numeric.html +201 -188
  37. data/doc/CSVDecision/Options.html +376 -357
  38. data/doc/CSVDecision/Parse.html +217 -204
  39. data/doc/CSVDecision/Paths.html +664 -629
  40. data/doc/CSVDecision/Result.html +1076 -1005
  41. data/doc/CSVDecision/Scan/InputHashes.html +305 -288
  42. data/doc/CSVDecision/Scan.html +262 -249
  43. data/doc/CSVDecision/ScanRow.html +749 -705
  44. data/doc/CSVDecision/Symbol.html +204 -191
  45. data/doc/CSVDecision/Table.html +1391 -1305
  46. data/doc/CSVDecision/TableValidationError.html +117 -110
  47. data/doc/CSVDecision/Validate.html +353 -337
  48. data/doc/CSVDecision.html +623 -552
  49. data/doc/_index.html +488 -448
  50. data/doc/class_list.html +250 -45
  51. data/doc/file.README.html +304 -278
  52. data/doc/index.html +304 -278
  53. data/doc/method_list.html +1159 -1017
  54. data/doc/top-level-namespace.html +79 -75
  55. data/lib/{csv_decision → csv_decision2}/columns.rb +7 -7
  56. data/lib/{csv_decision → csv_decision2}/data.rb +1 -1
  57. data/lib/{csv_decision → csv_decision2}/decision.rb +5 -5
  58. data/lib/{csv_decision → csv_decision2}/defaults.rb +2 -2
  59. data/lib/{csv_decision → csv_decision2}/dictionary.rb +2 -2
  60. data/lib/{csv_decision → csv_decision2}/header.rb +5 -5
  61. data/lib/{csv_decision → csv_decision2}/index.rb +5 -5
  62. data/lib/{csv_decision → csv_decision2}/input.rb +3 -3
  63. data/lib/{csv_decision → csv_decision2}/load.rb +6 -6
  64. data/lib/{csv_decision → csv_decision2}/matchers/constant.rb +2 -2
  65. data/lib/{csv_decision → csv_decision2}/matchers/function.rb +2 -2
  66. data/lib/{csv_decision → csv_decision2}/matchers/guard.rb +2 -2
  67. data/lib/{csv_decision → csv_decision2}/matchers/numeric.rb +2 -2
  68. data/lib/{csv_decision → csv_decision2}/matchers/pattern.rb +2 -2
  69. data/lib/{csv_decision → csv_decision2}/matchers/range.rb +2 -2
  70. data/lib/{csv_decision → csv_decision2}/matchers/symbol.rb +2 -2
  71. data/lib/{csv_decision → csv_decision2}/matchers.rb +5 -5
  72. data/lib/{csv_decision → csv_decision2}/options.rb +3 -3
  73. data/lib/{csv_decision → csv_decision2}/parse.rb +14 -14
  74. data/lib/{csv_decision → csv_decision2}/paths.rb +5 -5
  75. data/lib/{csv_decision → csv_decision2}/result.rb +2 -2
  76. data/lib/{csv_decision → csv_decision2}/scan.rb +3 -3
  77. data/lib/{csv_decision → csv_decision2}/scan_row.rb +2 -2
  78. data/lib/{csv_decision → csv_decision2}/table.rb +8 -8
  79. data/lib/{csv_decision → csv_decision2}/validate.rb +2 -2
  80. data/lib/csv_decision2.rb +45 -0
  81. data/spec/{csv_decision → csv_decision2}/columns_spec.rb +44 -44
  82. data/spec/{csv_decision → csv_decision2}/constant_spec.rb +4 -4
  83. data/spec/{csv_decision → csv_decision2}/data_spec.rb +11 -11
  84. data/spec/{csv_decision → csv_decision2}/decision_spec.rb +6 -6
  85. data/spec/{csv_decision → csv_decision2}/examples_spec.rb +14 -14
  86. data/spec/{csv_decision → csv_decision2}/index_spec.rb +8 -8
  87. data/spec/{csv_decision → csv_decision2}/input_spec.rb +9 -9
  88. data/spec/{csv_decision → csv_decision2}/load_spec.rb +8 -8
  89. data/spec/{csv_decision → csv_decision2}/matchers/function_spec.rb +7 -7
  90. data/spec/{csv_decision → csv_decision2}/matchers/guard_spec.rb +14 -14
  91. data/spec/{csv_decision → csv_decision2}/matchers/numeric_spec.rb +5 -5
  92. data/spec/{csv_decision → csv_decision2}/matchers/pattern_spec.rb +6 -6
  93. data/spec/{csv_decision → csv_decision2}/matchers/range_spec.rb +5 -5
  94. data/spec/{csv_decision → csv_decision2}/matchers/symbol_spec.rb +6 -6
  95. data/spec/{csv_decision → csv_decision2}/options_spec.rb +18 -18
  96. data/spec/csv_decision2/parse_spec.rb +44 -0
  97. data/spec/{csv_decision → csv_decision2}/table_spec.rb +17 -17
  98. data/spec/csv_decision2_spec.rb +7 -0
  99. metadata +64 -64
  100. data/lib/csv_decision.rb +0 -45
  101. data/spec/csv_decision/parse_spec.rb +0 -44
  102. data/spec/csv_decision_spec.rb +0 -7
data/doc/index.html CHANGED
@@ -1,23 +1,24 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>
7
- File: README
8
-
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>
8
+ File: README
9
+
9
10
  &mdash; Documentation by YARD 0.9.12
10
-
11
- </title>
11
+
12
+ </title>
12
13
 
13
14
  <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
15
 
15
16
  <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
17
 
17
- <script type="text/javascript" charset="utf-8">
18
- pathId = "README";
19
- relpath = '';
20
- </script>
18
+ <script type="text/javascript" charset="utf-8">
19
+ pathId = "README";
20
+ relpath = '';
21
+ </script>
21
22
 
22
23
 
23
24
  <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
@@ -25,93 +26,93 @@
25
26
  <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
27
 
27
28
 
28
- </head>
29
- <body>
30
- <div class="nav_wrap">
31
- <iframe id="nav" src="class_list.html?1"></iframe>
32
- <div id="resizer"></div>
33
- </div>
29
+ </head>
30
+
31
+ <body>
32
+ <div class="nav_wrap">
33
+ <iframe id="nav" src="class_list.html?1"></iframe>
34
+ <div id="resizer"></div>
35
+ </div>
36
+
37
+ <div id="main" tabindex="-1">
38
+ <div id="header">
39
+ <div id="menu">
40
+
41
+ <a href="_index.html">Index</a> &raquo;
42
+ <span class="title">File: README</span>
34
43
 
35
- <div id="main" tabindex="-1">
36
- <div id="header">
37
- <div id="menu">
38
-
39
- <a href="_index.html">Index</a> &raquo;
40
- <span class="title">File: README</span>
41
-
42
- </div>
43
-
44
- <div id="search">
45
-
46
- <a class="full_list_link" id="class_list_link"
47
- href="class_list.html">
48
-
49
- <svg width="24" height="24">
50
- <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
51
- <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
52
- <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
53
- </svg>
54
- </a>
55
-
56
- </div>
57
- <div class="clear"></div>
58
44
  </div>
59
45
 
60
- <div id="content"><div id='filecontents'>
61
- <h1 id="label-CSV+Decision">CSV Decision</h1>
46
+ <div id="search">
62
47
 
63
- <p><a href="https://badge.fury.io/rb/csv_decision"><img
64
- src="https://badge.fury.io/rb/csv_decision.svg"></a> <a
65
- href="https://travis-ci.org/bpvickers/csv_decision"><img
66
- src="https://travis-ci.org/bpvickers/csv_decision.svg?branch=master"></a>
67
- <a
68
- href="https://coveralls.io/github/bpvickers/csv_decision?branch=master"><img
69
- src="https://coveralls.io/repos/github/bpvickers/csv_decision/badge.svg?branch=master"></a>
70
- <a
71
- href="https://codeclimate.com/github/bpvickers/csv_decision/maintainability"><img
72
- src="https://api.codeclimate.com/v1/badges/466a6c52e8f6a3840967/maintainability"></a>
73
- <a href="#license"><img
74
- src="http://img.shields.io/badge/license-MIT-yellowgreen.svg"></a></p>
48
+ <a class="full_list_link" id="class_list_link" href="class_list.html">
75
49
 
76
- <h3 id="label-CSV+based+Ruby+decision+tables">CSV based Ruby decision tables</h3>
50
+ <svg width="24" height="24">
51
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
52
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
54
+ </svg>
55
+ </a>
77
56
 
78
- <p><code>csv_decision</code> is a RubyGem for CSV based <a
79
- href="https://en.wikipedia.org/wiki/Decision_table">decision tables</a>. It
80
- accepts decision tables implemented as a <a
81
- href="https://en.wikipedia.org/wiki/Comma-separated_values">CSV file</a>,
82
- which can then be used to execute complex conditional logic against an
83
- input hash, producing a decision as an output hash.</p>
57
+ </div>
58
+ <div class="clear"></div>
59
+ </div>
60
+
61
+ <div id="content">
62
+ <div id='filecontents'>
63
+ <h1 id="label-CSV+Decision">CSV Decision</h1>
64
+
65
+ <p><a href="https://badge.fury.io/rb/csv_decision"><img src="https://badge.fury.io/rb/csv_decision2.svg"></a> <a
66
+ href="https://travis-ci.org/bpvickers/csv_decision"><img
67
+ src="https://travis-ci.org/bpvickers/csv_decision2.svg?branch=master"></a>
68
+ <a href="https://coveralls.io/github/bpvickers/csv_decision?branch=master"><img
69
+ src="https://coveralls.io/repos/github/bpvickers/csv_decision2/badge.svg?branch=master"></a>
70
+ <a href="https://codeclimate.com/github/bpvickers/csv_decision2/maintainability"><img
71
+ src="https://api.codeclimate.com/v1/badges/466a6c52e8f6a3840967/maintainability"></a>
72
+ <a href="#license"><img src="http://img.shields.io/badge/license-MIT-yellowgreen.svg"></a>
73
+ </p>
74
+
75
+ <h3 id="label-CSV+based+Ruby+decision+tables">CSV based Ruby decision tables</h3>
84
76
 
85
- <h3 id="label-Why+use+csv_decision-3F">Why use <code>csv_decision</code>?</h3>
77
+ <p><code>csv_decision</code> is a RubyGem for CSV based <a
78
+ href="https://en.wikipedia.org/wiki/Decision_table">decision tables</a>. It
79
+ accepts decision tables implemented as a <a href="https://en.wikipedia.org/wiki/Comma-separated_values">CSV
80
+ file</a>,
81
+ which can then be used to execute complex conditional logic against an
82
+ input hash, producing a decision as an output hash.</p>
86
83
 
87
- <p>Typical “business logic” is notoriously illogical - full of corner cases
88
- and one-off exceptions. A decision table can express data-based decisions
89
- in a way that comes naturally to subject matter experts, who typically use
90
- spreadsheet models. Business logic can be encapsulated in a table, avoiding
91
- the need for tortuous conditional expressions.</p>
84
+ <h3 id="label-Why+use+csv_decision-3F">Why use <code>csv_decision</code>?</h3>
92
85
 
93
- <p>This gem and the examples below take inspiration from <a
94
- href="https://github.com/jmettraux/rufus-decision">rufus/decision</a>.
95
- (That gem is no longer maintained and CSV Decision has better decision-time
96
- performance, at the expense of slower table parse times and more memory –
97
- see <code>benchmarks/rufus_decision.rb</code>.)</p>
86
+ <p>Typical “business logic” is notoriously illogical - full of corner cases
87
+ and one-off exceptions. A decision table can express data-based decisions
88
+ in a way that comes naturally to subject matter experts, who typically use
89
+ spreadsheet models. Business logic can be encapsulated in a table, avoiding
90
+ the need for tortuous conditional expressions.</p>
98
91
 
99
- <h3 id="label-Installation">Installation</h3>
92
+ <p>This gem and the examples below take inspiration from <a
93
+ href="https://github.com/jmettraux/rufus-decision">rufus/decision</a>.
94
+ (That gem is no longer maintained and CSV Decision has better decision-time
95
+ performance, at the expense of slower table parse times and more memory –
96
+ see <code>benchmarks/rufus_decision.rb</code>.)</p>
100
97
 
101
- <p>To get started, just add <code>csv_decision</code> to your
102
- <code>Gemfile</code>, and then run <code>bundle</code>:</p>
98
+ <h3 id="label-Installation">Installation</h3>
103
99
 
104
- <p><code>ruby gem &#39;csv_decision&#39; </code></p>
100
+ <p>To get started, just add <code>csv_decision</code> to your
101
+ <code>Gemfile</code>, and then run <code>bundle</code>:
102
+ </p>
105
103
 
106
- <p>or simply <code>bash gem install csv_decision </code></p>
104
+ <p><code>ruby gem &#39;csv_decision&#39; </code></p>
107
105
 
108
- <h3 id="label-Simple+example">Simple example</h3>
106
+ <p>or simply <code>bash gem install csv_decision </code></p>
109
107
 
110
- <p>This table considers two input conditions: <code>topic</code> and
111
- <code>region</code>, labeled <code>in:</code>. Certain combinations yield
112
- an output value for <code>team_member</code>, labeled <code>out:</code>.</p>
108
+ <h3 id="label-Simple+example">Simple example</h3>
113
109
 
114
- <pre class="code ruby"><code class="ruby">in:topic | in:region | out:team_member
110
+ <p>This table considers two input conditions: <code>topic</code> and
111
+ <code>region</code>, labeled <code>in:</code>. Certain combinations yield
112
+ an output value for <code>team_member</code>, labeled <code>out:</code>.
113
+ </p>
114
+
115
+ <pre class="code ruby"><code class="ruby">in:topic | in:region | out:team_member
115
116
  ---------+------------+----------------
116
117
  sports | Europe | Alice
117
118
  sports | | Bob
@@ -123,151 +124,172 @@ politics | America | Gilbert
123
124
  politics | | Henry
124
125
  | | Zach</code></pre>
125
126
 
126
- <p>When the topic is <code>finance</code> and the region is
127
- <code>Europe</code> the team member <code>Donald</code> is selected. This
128
- is a “first match” decision table in that as soon as a match is made
129
- execution stops and a single output row (hash) is returned.</p>
127
+ <p>When the topic is <code>finance</code> and the region is
128
+ <code>Europe</code> the team member <code>Donald</code> is selected. This
129
+ is a “first match” decision table in that as soon as a match is made
130
+ execution stops and a single output row (hash) is returned.
131
+ </p>
130
132
 
131
- <p>The ordering of rows matters. <code>Ernest</code>, who is in charge of
132
- <code>finance</code> for the rest of the world, except for
133
- <code>America</code> and <code>Europe</code>, <em>must</em> come after his
134
- colleagues <code>Charlie</code> and <code>Donald</code>. <code>Zach</code>
135
- has been placed last, catching all the input combos not matching any other
136
- row.</p>
133
+ <p>The ordering of rows matters. <code>Ernest</code>, who is in charge of
134
+ <code>finance</code> for the rest of the world, except for
135
+ <code>America</code> and <code>Europe</code>, <em>must</em> come after his
136
+ colleagues <code>Charlie</code> and <code>Donald</code>. <code>Zach</code>
137
+ has been placed last, catching all the input combos not matching any other
138
+ row.
139
+ </p>
137
140
 
138
- <p>Here&#39;s the example as code:</p>
141
+ <p>Here&#39;s the example as code:</p>
139
142
 
140
- <p>“`ruby # Valid CSV string data = &lt;&lt;~DATA in :topic, in :region,
141
- out :team_member sports, Europe, Alice sports, , Bob finance, America,
142
- Charlie finance, Europe, Donald finance, , Ernest politics, Asia, Fujio
143
- politics, America, Gilbert politics, , Henry , , Zach DATA</p>
143
+ <p>“`ruby # Valid CSV string data = &lt;&lt;~DATA in :topic, in :region,
144
+ out :team_member sports, Europe, Alice sports, , Bob finance, America,
145
+ Charlie finance, Europe, Donald finance, , Ernest politics, Asia, Fujio
146
+ politics, America, Gilbert politics, , Henry , , Zach DATA</p>
144
147
 
145
- <p>table = CSVDecision.parse(data)</p>
148
+ <p>table = CSVDecision2.parse(data)</p>
146
149
 
147
- <p>table.decide(topic: &#39;finance&#39;, region: &#39;Europe&#39;) #=&gt; {
148
- team_member: &#39;Donald&#39; } table.decide(topic: &#39;sports&#39;,
149
- region: nil) #=&gt; { team_member: &#39;Bob&#39; } table.decide(topic:
150
- &#39;culture&#39;, region: &#39;America&#39;) #=&gt; { team_member:
151
- &#39;Zach&#39; } “`</p>
150
+ <p>table.decide(topic: &#39;finance&#39;, region: &#39;Europe&#39;) #=&gt; {
151
+ team_member: &#39;Donald&#39; } table.decide(topic: &#39;sports&#39;,
152
+ region: nil) #=&gt; { team_member: &#39;Bob&#39; } table.decide(topic:
153
+ &#39;culture&#39;, region: &#39;America&#39;) #=&gt; { team_member:
154
+ &#39;Zach&#39; } “`</p>
152
155
 
153
- <p>An empty <code>in:</code> cell means “matches any value”.</p>
156
+ <p>An empty <code>in:</code> cell means “matches any value”.</p>
154
157
 
155
- <p>Note that all column header names are symbolized, so it&#39;s actually more
156
- accurate to write <code>in :topic</code>; however spaces before and after
157
- the <code>:</code> do not matter.</p>
158
+ <p>Note that all column header names are symbolized, so it&#39;s actually more
159
+ accurate to write <code>in :topic</code>; however spaces before and after
160
+ the <code>:</code> do not matter.</p>
158
161
 
159
- <p>If you have cloned this gem&#39;s git repo, then the example can also be
160
- run by loading the table from a CSV file:</p>
162
+ <p>If you have cloned this gem&#39;s git repo, then the example can also be
163
+ run by loading the table from a CSV file:</p>
161
164
 
162
- <p><code>ruby table =
163
- CSVDecision.parse(Pathname(&#39;spec/data/valid/simple_example.csv&#39;))
165
+ <p><code>ruby table =
166
+ CSVDecision2.parse(Pathname(&#39;spec/data/valid/simple_example.csv&#39;))
164
167
  </code></p>
165
168
 
166
- <p>We can also load this same table using the option: <code>first_match:
169
+ <p>We can also load this same table using the option: <code>first_match:
167
170
  false</code>, which means that <em>all</em> matching rows will be
168
- accumulated into an array of hashes.</p>
171
+ accumulated into an array of hashes.</p>
169
172
 
170
- <p><code>ruby table = CSVDecision.parse(data, first_match: false)
173
+ <p><code>ruby table = CSVDecision2.parse(data, first_match: false)
171
174
  table.decide(topic: &#39;finance&#39;, region: &#39;Europe&#39;) #=&gt; {
172
175
  team_member: %w[Donald Ernest Zach] } </code></p>
173
176
 
174
- <p>For more examples see <code>spec/csv_decision/table_spec.rb</code>.
175
- Complete documentation of all table parameters is in the code - see
176
- <code>lib/csv_decision/parse.rb</code> and
177
- <code>lib/csv_decision/table.rb</code>.</p>
178
-
179
- <h3 id="label-CSV+Decision+features">CSV Decision features</h3>
180
- <ul><li>
181
- <p>Either returns the first matching row as a hash (default), or accumulates
182
- all matches as an array of hashes (i.e., <code>parse</code> option
183
- <code>first_match: false</code> or CSV file option
184
- <code>accumulate</code>).</p>
185
- </li><li>
186
- <p>Fast decision-time performance (see <code>benchmarks</code> folder).
187
- Automatically indexes all constants-only columns that do not contain any
188
- empty strings.</p>
189
- </li><li>
190
- <p>In addition to strings, can match basic Ruby constants (e.g.,
191
- <code>=nil</code>), regular expressions (e.g., <code>=~ on|off</code>),
192
- comparisons (e.g., <code>&gt; 100.0</code> ) and Ruby-style ranges (e.g.,
193
- <code>1..10</code>)</p>
194
- </li><li>
195
- <p>Can compare an input column versus another input hash key - e.g.,
196
- <code>&gt; :column</code>.</p>
197
- </li><li>
198
- <p>Any cell starting with <code>#</code> is treated as a comment, and comments
199
- may appear anywhere in the table.</p>
200
- </li><li>
201
- <p>Column symbol expressions or Ruby methods (0-arity) may be used in input
202
- columns for matching - e.g., <code>:column.zero?</code> or <code>:column
177
+ <p>For more examples see <code>spec/csv_decision2/table_spec.rb</code>.
178
+ Complete documentation of all table parameters is in the code - see
179
+ <code>lib/csv_decision2/parse.rb</code> and
180
+ <code>lib/csv_decision2/table.rb</code>.
181
+ </p>
182
+
183
+ <h3 id="label-CSV+Decision+features">CSV Decision features</h3>
184
+ <ul>
185
+ <li>
186
+ <p>Either returns the first matching row as a hash (default), or accumulates
187
+ all matches as an array of hashes (i.e., <code>parse</code> option
188
+ <code>first_match: false</code> or CSV file option
189
+ <code>accumulate</code>).
190
+ </p>
191
+ </li>
192
+ <li>
193
+ <p>Fast decision-time performance (see <code>benchmarks</code> folder).
194
+ Automatically indexes all constants-only columns that do not contain any
195
+ empty strings.</p>
196
+ </li>
197
+ <li>
198
+ <p>In addition to strings, can match basic Ruby constants (e.g.,
199
+ <code>=nil</code>), regular expressions (e.g., <code>=~ on|off</code>),
200
+ comparisons (e.g., <code>&gt; 100.0</code> ) and Ruby-style ranges (e.g.,
201
+ <code>1..10</code>)
202
+ </p>
203
+ </li>
204
+ <li>
205
+ <p>Can compare an input column versus another input hash key - e.g.,
206
+ <code>&gt; :column</code>.
207
+ </p>
208
+ </li>
209
+ <li>
210
+ <p>Any cell starting with <code>#</code> is treated as a comment, and comments
211
+ may appear anywhere in the table.</p>
212
+ </li>
213
+ <li>
214
+ <p>Column symbol expressions or Ruby methods (0-arity) may be used in input
215
+ columns for matching - e.g., <code>:column.zero?</code> or <code>:column
203
216
  == 0</code>.</p>
204
- </li><li>
205
- <p>May also use Ruby methods in output columns - e.g.,
206
- <code>:column.length</code>.</p>
207
- </li><li>
208
- <p>Accepts data as a file, CSV string or an array of arrays.</p>
209
- </li></ul>
210
-
211
- <h4 id="label-Constants+other+than+strings">Constants other than strings</h4>
212
-
213
- <p>Although <code>csv_decision</code> is string oriented, it does recognise
214
- other types of constant present in the input hash. Specifically, the
215
- following classes are recognized: <code>Integer</code>,
216
- <code>BigDecimal</code>, <code>NilClass</code>, <code>TrueClass</code> and
217
- <code>FalseClass</code>.</p>
218
-
219
- <p>This is accomplished by prefixing the value with one of the operators
220
- <code>=</code>, <code>==</code> or <code>:=</code>. (The syntax is
221
- intentionally lax.)</p>
222
-
223
- <p>For example: “`ruby data = &lt;&lt;~DATA in :constant, out :value
224
- :=nil, :=nil ==false, ==false =true, =true = 0, = 0 :=100.0, :=100.0
225
- DATA</p>
226
-
227
- <p>table = CSVDecision.parse(data) table.decide(constant: nil) # returns
228
- value: nil<br> table.decide(constant: 0) # returns value: 0<br>
229
- table.decide(constant: BigDecimal(&#39;100.0&#39;)) # returns value:
230
- BigDecimal(&#39;100.0&#39;)<br> “`</p>
231
-
232
- <h4 id="label-Column+header+symbols">Column header symbols</h4>
233
-
234
- <p>All input and output column names are symbolized, and those symbols may be
235
- used to form simple expressions that refer to values in the input hash.</p>
236
-
237
- <p>For example: “`ruby data = &lt;&lt;~DATA in :node, in :parent, out :top?
238
- , == :node, yes , , no DATA</p>
239
-
240
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CSVDecision.html" title="CSVDecision (module)">CSVDecision</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="CSVDecision.html#parse-class_method" title="CSVDecision.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
217
+ </li>
218
+ <li>
219
+ <p>May also use Ruby methods in output columns - e.g.,
220
+ <code>:column.length</code>.
221
+ </p>
222
+ </li>
223
+ <li>
224
+ <p>Accepts data as a file, CSV string or an array of arrays.</p>
225
+ </li>
226
+ </ul>
227
+
228
+ <h4 id="label-Constants+other+than+strings">Constants other than strings</h4>
229
+
230
+ <p>Although <code>csv_decision</code> is string oriented, it does recognise
231
+ other types of constant present in the input hash. Specifically, the
232
+ following classes are recognized: <code>Integer</code>,
233
+ <code>BigDecimal</code>, <code>NilClass</code>, <code>TrueClass</code> and
234
+ <code>FalseClass</code>.
235
+ </p>
236
+
237
+ <p>This is accomplished by prefixing the value with one of the operators
238
+ <code>=</code>, <code>==</code> or <code>:=</code>. (The syntax is
239
+ intentionally lax.)
240
+ </p>
241
+
242
+ <p>For example: “`ruby data = &lt;&lt;~DATA in :constant, out :value
243
+ :=nil, :=nil ==false, ==false =true, =true = 0, = 0 :=100.0, :=100.0
244
+ DATA</p>
245
+
246
+ <p>table = CSVDecision2.parse(data) table.decide(constant: nil) # returns
247
+ value: nil<br> table.decide(constant: 0) # returns value: 0<br>
248
+ table.decide(constant: BigDecimal(&#39;100.0&#39;)) # returns value:
249
+ BigDecimal(&#39;100.0&#39;)<br> “`</p>
250
+
251
+ <h4 id="label-Column+header+symbols">Column header symbols</h4>
252
+
253
+ <p>All input and output column names are symbolized, and those symbols may be
254
+ used to form simple expressions that refer to values in the input hash.</p>
255
+
256
+ <p>For example: “`ruby data = &lt;&lt;~DATA in :node, in :parent, out :top?
257
+ , == :node, yes , , no DATA</p>
258
+
259
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CSVDecision2.html" title="CSVDecision (module)">CSVDecision</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="CSVDecision2.html#parse-class_method" title="CSVDecision2.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
241
260
  <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_decide'>decide</span><span class='lparen'>(</span><span class='label'>node:</span> <span class='int'>0</span><span class='comma'>,</span> <span class='label'>parent:</span> <span class='int'>0</span><span class='rparen'>)</span> <span class='comment'># returns top?: &#39;yes&#39;
242
261
  </span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_decide'>decide</span><span class='lparen'>(</span><span class='label'>node:</span> <span class='int'>1</span><span class='comma'>,</span> <span class='label'>parent:</span> <span class='int'>0</span><span class='rparen'>)</span> <span class='comment'># returns top?: &#39;no&#39;
243
262
  </span></code></pre>
244
263
 
245
- <p>“`</p>
264
+ <p>“`</p>
246
265
 
247
- <p>Note that there is no need to include an input column for
248
- <code>:node</code> in the decision table - it just needs to be present in
249
- the input hash. The expression, <code>== :node</code> should be read as
250
- <code>:parent == :node</code>. It can also be shortened to just
251
- <code>:node</code>, so the above decision table may be simplified to:</p>
266
+ <p>Note that there is no need to include an input column for
267
+ <code>:node</code> in the decision table - it just needs to be present in
268
+ the input hash. The expression, <code>== :node</code> should be read as
269
+ <code>:parent == :node</code>. It can also be shortened to just
270
+ <code>:node</code>, so the above decision table may be simplified to:
271
+ </p>
252
272
 
253
- <p><code>ruby data = &lt;&lt;~DATA in :parent, out :top?
273
+ <p><code>ruby data = &lt;&lt;~DATA in :parent, out :top?
254
274
  :node, yes , no DATA </code> These comparison
255
- operators are also supported: <code>!=</code>, <code>&gt;</code>,
256
- <code>&gt;=</code>, <code>&lt;</code>, <code>&lt;=</code>. In addition, you
257
- can also apply a Ruby 0-arity method - e.g., <code>.present?</code> or
258
- <code>.nil?</code>. Negation is also supported - e.g., <code>!.nil?</code>.
259
- Note that <code>.nil?</code> can also be written as <code>:= nil?</code>,
260
- and <code>!.nil?</code> as <code>:= !nil?</code>, depending on preference.</p>
275
+ operators are also supported: <code>!=</code>, <code>&gt;</code>,
276
+ <code>&gt;=</code>, <code>&lt;</code>, <code>&lt;=</code>. In addition, you
277
+ can also apply a Ruby 0-arity method - e.g., <code>.present?</code> or
278
+ <code>.nil?</code>. Negation is also supported - e.g., <code>!.nil?</code>.
279
+ Note that <code>.nil?</code> can also be written as <code>:= nil?</code>,
280
+ and <code>!.nil?</code> as <code>:= !nil?</code>, depending on preference.
281
+ </p>
261
282
 
262
- <p>For more simple examples see
263
- <code>spec/csv_decision/examples_spec.rb</code>.</p>
283
+ <p>For more simple examples see
284
+ <code>spec/csv_decision2/examples_spec.rb</code>.
285
+ </p>
264
286
 
265
- <h4 id="label-Input+guard+conditions">Input <code>guard</code> conditions</h4>
287
+ <h4 id="label-Input+guard+conditions">Input <code>guard</code> conditions</h4>
266
288
 
267
- <p>Sometimes it&#39;s more convenient to write guard expressions in a single
268
- column specialized for that purpose. For example:</p>
289
+ <p>Sometimes it&#39;s more convenient to write guard expressions in a single
290
+ column specialized for that purpose. For example:</p>
269
291
 
270
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='heredoc_beg'>&lt;&lt;~DATA</span>
292
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='heredoc_beg'>&lt;&lt;~DATA</span>
271
293
  <span class='tstring_content'> in :country, guard:, out :ID, out :ID_type, out :len
272
294
  </span><span class='tstring_content'> US, :CUSIP.present?, :CUSIP, CUSIP, :ID.length
273
295
  </span><span class='tstring_content'> GB, :SEDOL.present?, :SEDOL, SEDOL, :ID.length
@@ -277,25 +299,26 @@ column specialized for that purpose. For example:</p>
277
299
  </span><span class='tstring_content'> , , := nil, := nil, := nil
278
300
  </span><span class='heredoc_end'>DATA
279
301
  </span>
280
- <span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CSVDecision.html" title="CSVDecision (module)">CSVDecision</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="CSVDecision.html#parse-class_method" title="CSVDecision.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
302
+ <span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CSVDecision2.html" title="CSVDecision (module)">CSVDecision</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="CSVDecision2.html#parse-class_method" title="CSVDecision2.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
281
303
  <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_decide'>decide</span><span class='lparen'>(</span><span class='label'>country:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>US</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>CUSIP:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>123456789</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; { ID: &#39;123456789&#39;, ID_type: &#39;CUSIP&#39;, len: 9 }
282
- </span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_decide'>decide</span><span class='lparen'>(</span><span class='label'>country:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>EU</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>CUSIP:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>123456789</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>ISIN:</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>123456789012</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
304
+ </span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_decide'>decide</span><span class='lparen'>(</span><span class='label'>country:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>EU</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>CUSIP:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>123456789</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>ISIN:</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>123456789012</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
283
305
  <span class='comment'>#=&gt; { ID: &#39;123456789012&#39;, ID_type: &#39;ISIN&#39;, len: 12 }
284
306
  </span></code></pre>
285
307
 
286
- <p>Input <code>guard:</code> columns may be anonymous, and must contain
287
- non-constant expressions. In addition to 0-arity Ruby methods, the
288
- following comparison operators are allowed: <code>==</code>,
289
- <code>!=</code>, <code>&gt;</code>, <code>&gt;=</code>, <code>&lt;</code>
290
- and <code>&lt;=</code>. Also, regular expressions are supported - i.e.,
291
- <code>=~</code> and <code>!~</code>.</p>
308
+ <p>Input <code>guard:</code> columns may be anonymous, and must contain
309
+ non-constant expressions. In addition to 0-arity Ruby methods, the
310
+ following comparison operators are allowed: <code>==</code>,
311
+ <code>!=</code>, <code>&gt;</code>, <code>&gt;=</code>, <code>&lt;</code>
312
+ and <code>&lt;=</code>. Also, regular expressions are supported - i.e.,
313
+ <code>=~</code> and <code>!~</code>.
314
+ </p>
292
315
 
293
- <h4 id="label-Output+if+conditions">Output <code>if</code> conditions</h4>
316
+ <h4 id="label-Output+if+conditions">Output <code>if</code> conditions</h4>
294
317
 
295
- <p>In some situations it is useful to apply filter conditions <em>after</em>
296
- all the output columns have been derived. For example:</p>
318
+ <p>In some situations it is useful to apply filter conditions <em>after</em>
319
+ all the output columns have been derived. For example:</p>
297
320
 
298
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='heredoc_beg'>&lt;&lt;~DATA</span>
321
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='heredoc_beg'>&lt;&lt;~DATA</span>
299
322
  <span class='tstring_content'> in :country, guard:, out :ID, out :ID_type, out :len, if:
300
323
  </span><span class='tstring_content'> US, :CUSIP.present?, :CUSIP, CUSIP8, :ID.length, :len == 8
301
324
  </span><span class='tstring_content'> US, :CUSIP.present?, :CUSIP, CUSIP9, :ID.length, :len == 9
@@ -305,29 +328,31 @@ all the output columns have been derived. For example:</p>
305
328
  </span><span class='tstring_content'> , :CUSIP.present?, :CUSIP, DUMMY, :ID.length,
306
329
  </span><span class='heredoc_end'> DATA
307
330
  </span>
308
- <span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CSVDecision.html" title="CSVDecision (module)">CSVDecision</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="CSVDecision.html#parse-class_method" title="CSVDecision.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
331
+ <span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CSVDecision2.html" title="CSVDecision (module)">CSVDecision</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="CSVDecision2.html#parse-class_method" title="CSVDecision2.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
309
332
  <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_decide'>decide</span><span class='lparen'>(</span><span class='label'>country:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>US</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>CUSIP:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>123456789</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; {ID: &#39;123456789&#39;, ID_type: &#39;CUSIP9&#39;, len: 9}
310
333
  </span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_decide'>decide</span><span class='lparen'>(</span><span class='label'>CUSIP:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>12345678</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>ISIN:</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>1234567890</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; {ID: &#39;1234567890&#39;, ID_type: &#39;DUMMY&#39;, len: 10}
311
334
  </span></code></pre>
312
335
 
313
- <p>Output <code>if:</code> columns may be anonymous, and must contain
314
- non-constant expressions. In addition to 0-arity Ruby methods, the
315
- following comparison operators are allowed: <code>==</code>,
316
- <code>!=</code>, <code>&gt;</code>, <code>&gt;=</code>, <code>&lt;</code>
317
- and <code>&lt;=</code>. Also, regular expressions are supported - i.e.,
318
- <code>=~</code> and <code>!~</code>.</p>
319
-
320
- <h4 id="label-Input+set+columns">Input <code>set</code> columns</h4>
321
-
322
- <p>If you wish to set default values in the input hash, you can use a
323
- <code>set</code> column rather than an <code>in</code> column. The data row
324
- beneath the header is used to specify the default expression. There are
325
- three variations: <code>set</code> (unconditional default)
326
- <code>set/nil?</code>(set if <code>nil?</code> true) and
327
- <code>set/blank?</code> (set if <code>blank?</code> true). Note that the
328
- <code>decide!</code> method will mutate the input hash.</p>
329
-
330
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='heredoc_beg'>&lt;&lt;~DATA</span>
336
+ <p>Output <code>if:</code> columns may be anonymous, and must contain
337
+ non-constant expressions. In addition to 0-arity Ruby methods, the
338
+ following comparison operators are allowed: <code>==</code>,
339
+ <code>!=</code>, <code>&gt;</code>, <code>&gt;=</code>, <code>&lt;</code>
340
+ and <code>&lt;=</code>. Also, regular expressions are supported - i.e.,
341
+ <code>=~</code> and <code>!~</code>.
342
+ </p>
343
+
344
+ <h4 id="label-Input+set+columns">Input <code>set</code> columns</h4>
345
+
346
+ <p>If you wish to set default values in the input hash, you can use a
347
+ <code>set</code> column rather than an <code>in</code> column. The data row
348
+ beneath the header is used to specify the default expression. There are
349
+ three variations: <code>set</code> (unconditional default)
350
+ <code>set/nil?</code>(set if <code>nil?</code> true) and
351
+ <code>set/blank?</code> (set if <code>blank?</code> true). Note that the
352
+ <code>decide!</code> method will mutate the input hash.
353
+ </p>
354
+
355
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='heredoc_beg'>&lt;&lt;~DATA</span>
331
356
  <span class='tstring_content'> set/nil? :country, guard:, set: class, out :PAID, out: len, if:
332
357
  </span><span class='tstring_content'> US, , :class.upcase,
333
358
  </span><span class='tstring_content'> US, :CUSIP.present?, != PRIVATE, :CUSIP, :PAID.length, :len == 9
@@ -336,86 +361,87 @@ three variations: <code>set</code> (unconditional default)
336
361
  </span><span class='tstring_content'> !=US, :ISIN.present?, PRIVATE, :ISIN, :PAID.length,
337
362
  </span><span class='heredoc_end'>DATA
338
363
  </span>
339
- <span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CSVDecision.html" title="CSVDecision (module)">CSVDecision</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="CSVDecision.html#parse-class_method" title="CSVDecision.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
364
+ <span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CSVDecision2.html" title="CSVDecision (module)">CSVDecision</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="CSVDecision2.html#parse-class_method" title="CSVDecision2.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
340
365
  <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_decide'>decide</span><span class='lparen'>(</span><span class='label'>CUSIP:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>1234567890</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>class:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Private</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; {PAID: &#39;1234567890&#39;, len: 10}
341
366
  </span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_decide'>decide</span><span class='lparen'>(</span><span class='label'>ISIN:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>123456789012</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>country:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>GB</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>class:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>private</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; {PAID: &#39;123456789012&#39;, len: 12}
342
367
  </span></code></pre>
343
368
 
344
- <h4 id="label-Input+path+columns">Input <code>path</code> columns</h4>
369
+ <h4 id="label-Input+path+columns">Input <code>path</code> columns</h4>
345
370
 
346
- <p>For hashes that contain sub-hashes, it&#39;s possible to specify a path for
347
- the purposes of matching. (Arrays are currently not supported.)</p>
371
+ <p>For hashes that contain sub-hashes, it&#39;s possible to specify a path for
372
+ the purposes of matching. (Arrays are currently not supported.)</p>
348
373
 
349
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='heredoc_beg'>&lt;&lt;~DATA</span>
374
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='heredoc_beg'>&lt;&lt;~DATA</span>
350
375
  <span class='tstring_content'> path:, path:, out :value
351
376
  </span><span class='tstring_content'> header, , :source_name
352
377
  </span><span class='tstring_content'> header, metrics, :service_name
353
378
  </span><span class='tstring_content'> payload, , :amount
354
379
  </span><span class='tstring_content'> payload, ref_data, :account_id
355
380
  </span><span class='heredoc_end'>DATA
356
- </span><span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CSVDecision.html" title="CSVDecision (module)">CSVDecision</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="CSVDecision.html#parse-class_method" title="CSVDecision.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='label'>first_match:</span> <span class='kw'>false</span><span class='rparen'>)</span>
381
+ </span><span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="CSVDecision2.html" title="CSVDecision (module)">CSVDecision</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="CSVDecision2.html#parse-class_method" title="CSVDecision2.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='label'>first_match:</span> <span class='kw'>false</span><span class='rparen'>)</span>
357
382
 
358
383
  <span class='id identifier rubyid_input'>input</span> <span class='op'>=</span> <span class='lbrace'>{</span>
359
- <span class='label'>header:</span> <span class='lbrace'>{</span>
384
+ <span class='label'>header:</span> <span class='lbrace'>{</span>
360
385
  <span class='label'>id:</span> <span class='int'>1</span><span class='comma'>,</span> <span class='label'>type_cd:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>BUY</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>source_name:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Client</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>client_name:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>AAPL</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
361
- <span class='label'>metrics:</span> <span class='lbrace'>{</span> <span class='label'>service_name:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Trading</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>receive_time:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>12:00</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
386
+ <span class='label'>metrics:</span> <span class='lbrace'>{</span> <span class='label'>service_name:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Trading</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>receive_time:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>12:00</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
362
387
  <span class='rbrace'>}</span><span class='comma'>,</span>
363
- <span class='label'>payload:</span> <span class='lbrace'>{</span>
388
+ <span class='label'>payload:</span> <span class='lbrace'>{</span>
364
389
  <span class='label'>tran_id:</span> <span class='int'>9</span><span class='comma'>,</span> <span class='label'>amount:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>100.00</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span>
365
- <span class='label'>ref_data:</span> <span class='lbrace'>{</span> <span class='label'>account_id:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>5010</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>type_id:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>BUYL</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
390
+ <span class='label'>ref_data:</span> <span class='lbrace'>{</span> <span class='label'>account_id:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>5010</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='label'>type_id:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>BUYL</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
366
391
  <span class='rbrace'>}</span>
367
392
  <span class='rbrace'>}</span>
368
393
 
369
394
  <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_decide'>decide</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span> <span class='comment'>#=&gt; { value: %w[Client Trading 100.00 5010] }
370
395
  </span></code></pre>
371
396
 
372
- <h3 id="label-Testing">Testing</h3>
397
+ <h3 id="label-Testing">Testing</h3>
373
398
 
374
- <p><code>csv_decision</code> includes thorough <a
375
- href="http://rspec.info">RSpec</a> tests:</p>
399
+ <p><code>csv_decision</code> includes thorough <a href="http://rspec.info">RSpec</a> tests:</p>
376
400
 
377
- <p><code>bash # Execute within a clone of the csv_decision Git repository:
401
+ <p><code>bash # Execute within a clone of the csv_decision Git repository:
378
402
  bundle install rspec </code></p>
379
403
 
380
- <h3 id="label-Planned+features">Planned features</h3>
404
+ <h3 id="label-Planned+features">Planned features</h3>
381
405
 
382
- <p><code>csv_decision</code> is still a work in progress, and will be enhanced
383
- to support the following features: * Supply a pre-defined library of
384
- functions that may be called within input columns to implement custom
385
- matching logic, or from the output columns to formulate the final
386
- decision. * Built-in lookup functions evaluate other decision tables to
387
- implement guard conditions, or supply output values. * Available
388
- functions may be extended with a user-supplied library of Ruby methods for
389
- custom logic. * Output columns may construct interpolated strings
390
- containing references to column symbols.</p>
406
+ <p><code>csv_decision</code> is still a work in progress, and will be enhanced
407
+ to support the following features: * Supply a pre-defined library of
408
+ functions that may be called within input columns to implement custom
409
+ matching logic, or from the output columns to formulate the final
410
+ decision. * Built-in lookup functions evaluate other decision tables to
411
+ implement guard conditions, or supply output values. * Available
412
+ functions may be extended with a user-supplied library of Ruby methods for
413
+ custom logic. * Output columns may construct interpolated strings
414
+ containing references to column symbols.</p>
391
415
 
392
- <h3 id="label-Reasons+for+the+limitations+of+column+expressions">Reasons for the limitations of column expressions</h3>
416
+ <h3 id="label-Reasons+for+the+limitations+of+column+expressions">Reasons for the limitations of column
417
+ expressions</h3>
393
418
 
394
- <p>The simple column expressions allowed by <code>csv_decision</code> are
395
- purposely limited for reasons of understandability and maintainability. The
396
- whole point of this gem is to make decision rules easier to express and
397
- comprehend as declarative, tabular logic. While Ruby makes it easy to
398
- execute arbitrary code embedded within a CSV file, this could easily result
399
- in hard to debug logic that also poses safety risks.</p>
419
+ <p>The simple column expressions allowed by <code>csv_decision</code> are
420
+ purposely limited for reasons of understandability and maintainability. The
421
+ whole point of this gem is to make decision rules easier to express and
422
+ comprehend as declarative, tabular logic. While Ruby makes it easy to
423
+ execute arbitrary code embedded within a CSV file, this could easily result
424
+ in hard to debug logic that also poses safety risks.</p>
400
425
 
401
- <h2 id="label-Changelog">Changelog</h2>
426
+ <h2 id="label-Changelog">Changelog</h2>
402
427
 
403
- <p>See <a href="./CHANGELOG.md">CHANGELOG.md</a> for a list of changes.</p>
428
+ <p>See <a href="./CHANGELOG.md">CHANGELOG.md</a> for a list of changes.</p>
404
429
 
405
- <h2 id="label-License">License</h2>
430
+ <h2 id="label-License">License</h2>
406
431
 
407
- <p>CSV Decision © 2017-2018 by <a
408
- href="mailto:brett@phillips-vickers.com">Brett Vickers</a>. CSV Decision is
409
- licensed under the MIT license. Please see the <a
410
- href="./LICENSE">LICENSE</a> document for more information.</p>
411
- </div></div>
412
-
413
- <div id="footer">
414
- Generated on Sun Feb 11 10:26:06 2018 by
415
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
416
- 0.9.12 (ruby-2.4.0).
417
- </div>
432
+ <p>CSV Decision © 2017-2018 by <a href="mailto:brett@phillips-vickers.com">Brett Vickers</a>. CSV Decision is
433
+ licensed under the MIT license. Please see the <a href="./LICENSE">LICENSE</a> document for more information.
434
+ </p>
435
+ </div>
436
+ </div>
418
437
 
438
+ <div id="footer">
439
+ Generated on Sun Feb 11 10:26:06 2018 by
440
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
441
+ 0.9.12 (ruby-2.4.0).
419
442
  </div>
420
- </body>
421
- </html>
443
+
444
+ </div>
445
+ </body>
446
+
447
+ </html>