csv_decision2 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/README.md +16 -16
- data/benchmarks/rufus_decision.rb +5 -7
- data/csv_decision2.gemspec +2 -2
- data/doc/CSVDecision/CellValidationError.html +117 -110
- data/doc/CSVDecision/Columns/Default.html +537 -508
- data/doc/CSVDecision/Columns/Dictionary.html +729 -686
- data/doc/CSVDecision/Columns/Entry.html +457 -433
- data/doc/CSVDecision/Columns.html +1134 -1051
- data/doc/CSVDecision/Constant.html +205 -191
- data/doc/CSVDecision/Data.html +423 -398
- data/doc/CSVDecision/Decide.html +236 -225
- data/doc/CSVDecision/Decision.html +872 -825
- data/doc/CSVDecision/Defaults.html +243 -230
- data/doc/CSVDecision/Dictionary/Entry.html +1026 -964
- data/doc/CSVDecision/Dictionary.html +377 -355
- data/doc/CSVDecision/Error.html +116 -105
- data/doc/CSVDecision/FileError.html +117 -110
- data/doc/CSVDecision/Function.html +181 -168
- data/doc/CSVDecision/Guard.html +200 -185
- data/doc/CSVDecision/Header.html +557 -523
- data/doc/CSVDecision/Index.html +652 -617
- data/doc/CSVDecision/Input.html +329 -312
- data/doc/CSVDecision/Load.html +232 -220
- data/doc/CSVDecision/Matchers/Constant.html +432 -399
- data/doc/CSVDecision/Matchers/Function.html +451 -415
- data/doc/CSVDecision/Matchers/Guard.html +459 -424
- data/doc/CSVDecision/Matchers/Matcher.html +470 -426
- data/doc/CSVDecision/Matchers/Numeric.html +375 -346
- data/doc/CSVDecision/Matchers/Pattern.html +429 -396
- data/doc/CSVDecision/Matchers/Proc.html +617 -575
- data/doc/CSVDecision/Matchers/Range.html +331 -302
- data/doc/CSVDecision/Matchers/Symbol.html +386 -353
- data/doc/CSVDecision/Matchers.html +1509 -1393
- data/doc/CSVDecision/Numeric.html +201 -188
- data/doc/CSVDecision/Options.html +376 -357
- data/doc/CSVDecision/Parse.html +217 -204
- data/doc/CSVDecision/Paths.html +664 -629
- data/doc/CSVDecision/Result.html +1076 -1005
- data/doc/CSVDecision/Scan/InputHashes.html +305 -288
- data/doc/CSVDecision/Scan.html +262 -249
- data/doc/CSVDecision/ScanRow.html +749 -705
- data/doc/CSVDecision/Symbol.html +204 -191
- data/doc/CSVDecision/Table.html +1391 -1305
- data/doc/CSVDecision/TableValidationError.html +117 -110
- data/doc/CSVDecision/Validate.html +353 -337
- data/doc/CSVDecision.html +623 -552
- data/doc/_index.html +488 -448
- data/doc/class_list.html +250 -45
- data/doc/file.README.html +304 -278
- data/doc/index.html +304 -278
- data/doc/method_list.html +1159 -1017
- data/doc/top-level-namespace.html +79 -75
- data/lib/{csv_decision → csv_decision2}/columns.rb +7 -7
- data/lib/{csv_decision → csv_decision2}/data.rb +1 -1
- data/lib/{csv_decision → csv_decision2}/decision.rb +5 -5
- data/lib/{csv_decision → csv_decision2}/defaults.rb +2 -2
- data/lib/{csv_decision → csv_decision2}/dictionary.rb +2 -2
- data/lib/{csv_decision → csv_decision2}/header.rb +5 -5
- data/lib/{csv_decision → csv_decision2}/index.rb +5 -5
- data/lib/{csv_decision → csv_decision2}/input.rb +3 -3
- data/lib/{csv_decision → csv_decision2}/load.rb +6 -6
- data/lib/{csv_decision → csv_decision2}/matchers/constant.rb +2 -2
- data/lib/{csv_decision → csv_decision2}/matchers/function.rb +2 -2
- data/lib/{csv_decision → csv_decision2}/matchers/guard.rb +2 -2
- data/lib/{csv_decision → csv_decision2}/matchers/numeric.rb +2 -2
- data/lib/{csv_decision → csv_decision2}/matchers/pattern.rb +2 -2
- data/lib/{csv_decision → csv_decision2}/matchers/range.rb +2 -2
- data/lib/{csv_decision → csv_decision2}/matchers/symbol.rb +2 -2
- data/lib/{csv_decision → csv_decision2}/matchers.rb +5 -5
- data/lib/{csv_decision → csv_decision2}/options.rb +3 -3
- data/lib/{csv_decision → csv_decision2}/parse.rb +14 -14
- data/lib/{csv_decision → csv_decision2}/paths.rb +5 -5
- data/lib/{csv_decision → csv_decision2}/result.rb +2 -2
- data/lib/{csv_decision → csv_decision2}/scan.rb +3 -3
- data/lib/{csv_decision → csv_decision2}/scan_row.rb +2 -2
- data/lib/{csv_decision → csv_decision2}/table.rb +8 -8
- data/lib/{csv_decision → csv_decision2}/validate.rb +2 -2
- data/lib/csv_decision2.rb +45 -0
- data/spec/{csv_decision → csv_decision2}/columns_spec.rb +44 -44
- data/spec/{csv_decision → csv_decision2}/constant_spec.rb +4 -4
- data/spec/{csv_decision → csv_decision2}/data_spec.rb +11 -11
- data/spec/{csv_decision → csv_decision2}/decision_spec.rb +6 -6
- data/spec/{csv_decision → csv_decision2}/examples_spec.rb +14 -14
- data/spec/{csv_decision → csv_decision2}/index_spec.rb +8 -8
- data/spec/{csv_decision → csv_decision2}/input_spec.rb +9 -9
- data/spec/{csv_decision → csv_decision2}/load_spec.rb +8 -8
- data/spec/{csv_decision → csv_decision2}/matchers/function_spec.rb +7 -7
- data/spec/{csv_decision → csv_decision2}/matchers/guard_spec.rb +14 -14
- data/spec/{csv_decision → csv_decision2}/matchers/numeric_spec.rb +5 -5
- data/spec/{csv_decision → csv_decision2}/matchers/pattern_spec.rb +6 -6
- data/spec/{csv_decision → csv_decision2}/matchers/range_spec.rb +5 -5
- data/spec/{csv_decision → csv_decision2}/matchers/symbol_spec.rb +6 -6
- data/spec/{csv_decision → csv_decision2}/options_spec.rb +18 -18
- data/spec/csv_decision2/parse_spec.rb +44 -0
- data/spec/{csv_decision → csv_decision2}/table_spec.rb +17 -17
- data/spec/csv_decision2_spec.rb +7 -0
- metadata +64 -64
- data/lib/csv_decision.rb +0 -45
- data/spec/csv_decision/parse_spec.rb +0 -44
- 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
|
-
|
|
4
|
-
|
|
5
|
-
<meta
|
|
6
|
-
<
|
|
7
|
-
|
|
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
|
— 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
|
-
|
|
19
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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> »
|
|
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> »
|
|
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="
|
|
61
|
-
<h1 id="label-CSV+Decision">CSV Decision</h1>
|
|
46
|
+
<div id="search">
|
|
62
47
|
|
|
63
|
-
<
|
|
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
|
-
<
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
<
|
|
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
|
-
<
|
|
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>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
<
|
|
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
|
-
<
|
|
102
|
-
<code>Gemfile</code>, and then run <code>bundle</code>:</p>
|
|
98
|
+
<h3 id="label-Installation">Installation</h3>
|
|
103
99
|
|
|
104
|
-
<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
|
|
104
|
+
<p><code>ruby gem 'csv_decision' </code></p>
|
|
107
105
|
|
|
108
|
-
<
|
|
106
|
+
<p>or simply <code>bash gem install csv_decision </code></p>
|
|
109
107
|
|
|
110
|
-
<
|
|
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
|
-
<
|
|
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
|
|
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
|
|
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's the example as code:</p>
|
|
141
|
+
<p>Here's the example as code:</p>
|
|
139
142
|
|
|
140
|
-
<p>“`ruby
|
|
141
|
-
out :team_member
|
|
142
|
-
Charlie
|
|
143
|
-
politics, America, Gilbert
|
|
143
|
+
<p>“`ruby # Valid CSV string data = <<~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 =
|
|
148
|
+
<p>table = CSVDecision2.parse(data)</p>
|
|
146
149
|
|
|
147
|
-
<p>table.decide(topic: 'finance', region: 'Europe') #=> {
|
|
148
|
-
team_member: 'Donald' }
|
|
149
|
-
region: nil) #=> { team_member: 'Bob' }
|
|
150
|
-
'culture', region: 'America') #=> { team_member:
|
|
151
|
-
'Zach' } “`</p>
|
|
150
|
+
<p>table.decide(topic: 'finance', region: 'Europe') #=> {
|
|
151
|
+
team_member: 'Donald' } table.decide(topic: 'sports',
|
|
152
|
+
region: nil) #=> { team_member: 'Bob' } table.decide(topic:
|
|
153
|
+
'culture', region: 'America') #=> { team_member:
|
|
154
|
+
'Zach' } “`</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'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'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'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'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
|
-
|
|
165
|
+
<p><code>ruby table =
|
|
166
|
+
CSVDecision2.parse(Pathname('spec/data/valid/simple_example.csv'))
|
|
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 =
|
|
173
|
+
<p><code>ruby table = CSVDecision2.parse(data, first_match: false)
|
|
171
174
|
table.decide(topic: 'finance', region: 'Europe') #=> {
|
|
172
175
|
team_member: %w[Donald Ernest Zach] } </code></p>
|
|
173
176
|
|
|
174
|
-
<p>For more examples see <code>spec/
|
|
175
|
-
Complete documentation of all table parameters is in the code - see
|
|
176
|
-
<code>lib/
|
|
177
|
-
<code>lib/
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
<
|
|
181
|
-
<
|
|
182
|
-
|
|
183
|
-
<
|
|
184
|
-
<code>
|
|
185
|
-
</
|
|
186
|
-
<
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
<p>
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
<p>
|
|
196
|
-
<code
|
|
197
|
-
</
|
|
198
|
-
<
|
|
199
|
-
|
|
200
|
-
</li
|
|
201
|
-
<
|
|
202
|
-
|
|
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>> 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>> :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
|
|
205
|
-
<
|
|
206
|
-
<
|
|
207
|
-
</
|
|
208
|
-
|
|
209
|
-
</li
|
|
210
|
-
|
|
211
|
-
<
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
<code>
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
<code
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
<
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
<
|
|
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 = <<~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('100.0')) # returns value:
|
|
249
|
+
BigDecimal('100.0')<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 = <<~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?: 'yes'
|
|
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?: 'no'
|
|
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
|
|
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 = <<~DATA in :parent, out :top?
|
|
273
|
+
<p><code>ruby data = <<~DATA in :parent, out :top?
|
|
254
274
|
:node, yes , no DATA </code> These comparison
|
|
255
|
-
operators are also supported: <code>!=</code>, <code>></code>,
|
|
256
|
-
<code>>=</code>, <code><</code>, <code><=</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
|
|
275
|
+
operators are also supported: <code>!=</code>, <code>></code>,
|
|
276
|
+
<code>>=</code>, <code><</code>, <code><=</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/
|
|
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's more convenient to write guard expressions in a single
|
|
268
|
-
column specialized for that purpose. For example:</p>
|
|
289
|
+
<p>Sometimes it'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'><<~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'><<~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="
|
|
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'>'</span><span class='tstring_content'>US</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>CUSIP:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>123456789</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> { ID: '123456789', ID_type: 'CUSIP', 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'>'</span><span class='tstring_content'>EU</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>CUSIP:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>123456789</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>ISIN:</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>123456789012</span><span class='tstring_end'>'</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'>'</span><span class='tstring_content'>EU</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>CUSIP:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>123456789</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>ISIN:</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>123456789012</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
283
305
|
<span class='comment'>#=> { ID: '123456789012', ID_type: 'ISIN', 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>></code>, <code>>=</code>, <code><</code>
|
|
290
|
-
and <code><=</code>. Also, regular expressions are supported - i.e.,
|
|
291
|
-
<code>=~</code> and <code>!~</code
|
|
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>></code>, <code>>=</code>, <code><</code>
|
|
312
|
+
and <code><=</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'><<~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'><<~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="
|
|
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'>'</span><span class='tstring_content'>US</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>CUSIP:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>123456789</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> {ID: '123456789', ID_type: 'CUSIP9', 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'>'</span><span class='tstring_content'>12345678</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>ISIN:</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1234567890</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> {ID: '1234567890', ID_type: 'DUMMY', 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>></code>, <code>>=</code>, <code><</code>
|
|
317
|
-
and <code><=</code>. Also, regular expressions are supported - i.e.,
|
|
318
|
-
<code>=~</code> and <code>!~</code
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
<
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
<code>set
|
|
327
|
-
<code>set/
|
|
328
|
-
<code>
|
|
329
|
-
|
|
330
|
-
|
|
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>></code>, <code>>=</code>, <code><</code>
|
|
340
|
+
and <code><=</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'><<~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="
|
|
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'>'</span><span class='tstring_content'>1234567890</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>class:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Private</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> {PAID: '1234567890', 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'>'</span><span class='tstring_content'>123456789012</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>country:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>GB</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>class:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>private</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> {PAID: '123456789012', 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'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'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'><<~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'><<~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="
|
|
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'>'</span><span class='tstring_content'>BUY</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>source_name:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Client</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>client_name:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>AAPL</span><span class='tstring_end'>'</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'>'</span><span class='tstring_content'>Trading</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>receive_time:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>12:00</span><span class='tstring_end'>'</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'>'</span><span class='tstring_content'>Trading</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>receive_time:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>12:00</span><span class='tstring_end'>'</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'>'</span><span class='tstring_content'>100.00</span><span class='tstring_end'>'</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'>'</span><span class='tstring_content'>5010</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>type_id:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>BUYL</span><span class='tstring_end'>'</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'>'</span><span class='tstring_content'>5010</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>type_id:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>BUYL</span><span class='tstring_end'>'</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'>#=> { 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
|
|
384
|
-
functions that may be called within input columns to
|
|
385
|
-
matching logic, or from the output columns to formulate the final
|
|
386
|
-
decision.
|
|
387
|
-
implement guard conditions,
|
|
388
|
-
functions may be extended with a user-supplied library of Ruby methods
|
|
389
|
-
custom logic.
|
|
390
|
-
containing references to column
|
|
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
|
|
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="
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
</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
|
-
|
|
421
|
-
</
|
|
443
|
+
|
|
444
|
+
</div>
|
|
445
|
+
</body>
|
|
446
|
+
|
|
447
|
+
</html>
|