csv_decision 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -0
- data/.gitignore +2 -1
- data/.travis.yml +2 -3
- data/CHANGELOG.md +19 -1
- data/README.md +49 -16
- data/{benchmark.rb → benchmarks/rufus_decision.rb} +1 -1
- data/csv_decision.gemspec +1 -1
- data/doc/CSVDecision/CellValidationError.html +143 -0
- data/doc/CSVDecision/Columns/Default.html +409 -0
- data/doc/CSVDecision/Columns/Dictionary.html +410 -0
- data/doc/CSVDecision/Columns/Entry.html +321 -0
- data/doc/CSVDecision/Columns.html +476 -0
- data/doc/CSVDecision/Constant.html +295 -0
- data/doc/CSVDecision/Data.html +344 -0
- data/doc/CSVDecision/Decide.html +434 -0
- data/doc/CSVDecision/Decision.html +604 -0
- data/doc/CSVDecision/Error.html +139 -0
- data/doc/CSVDecision/FileError.html +143 -0
- data/doc/CSVDecision/Function.html +229 -0
- data/doc/CSVDecision/Header.html +520 -0
- data/doc/CSVDecision/Input.html +305 -0
- data/doc/CSVDecision/Load.html +225 -0
- data/doc/CSVDecision/Matchers/Constant.html +242 -0
- data/doc/CSVDecision/Matchers/Function.html +342 -0
- data/doc/CSVDecision/Matchers/Matcher.html +325 -0
- data/doc/CSVDecision/Matchers/Numeric.html +277 -0
- data/doc/CSVDecision/Matchers/Pattern.html +600 -0
- data/doc/CSVDecision/Matchers/Range.html +413 -0
- data/doc/CSVDecision/Matchers/Symbol.html +280 -0
- data/doc/CSVDecision/Matchers.html +1529 -0
- data/doc/CSVDecision/Numeric.html +259 -0
- data/doc/CSVDecision/Options.html +445 -0
- data/doc/CSVDecision/Parse.html +270 -0
- data/doc/CSVDecision/ScanRow.html +746 -0
- data/doc/CSVDecision/Symbol.html +256 -0
- data/doc/CSVDecision/Table.html +1115 -0
- data/doc/CSVDecision.html +652 -0
- data/doc/_index.html +410 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +499 -0
- data/doc/file.README.html +264 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +264 -0
- data/doc/js/app.js +248 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +683 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/csv_decision/columns.rb +15 -12
- data/lib/csv_decision/constant.rb +54 -0
- data/lib/csv_decision/decide.rb +5 -5
- data/lib/csv_decision/decision.rb +3 -1
- data/lib/csv_decision/function.rb +32 -0
- data/lib/csv_decision/header.rb +27 -18
- data/lib/csv_decision/input.rb +11 -8
- data/lib/csv_decision/matchers/constant.rb +18 -0
- data/lib/csv_decision/matchers/function.rb +11 -44
- data/lib/csv_decision/matchers/numeric.rb +5 -33
- data/lib/csv_decision/matchers/pattern.rb +26 -11
- data/lib/csv_decision/matchers/range.rb +21 -5
- data/lib/csv_decision/matchers/symbol.rb +20 -0
- data/lib/csv_decision/matchers.rb +85 -20
- data/lib/csv_decision/numeric.rb +38 -0
- data/lib/csv_decision/options.rb +36 -27
- data/lib/csv_decision/parse.rb +46 -39
- data/lib/csv_decision/scan_row.rb +19 -7
- data/lib/csv_decision/symbol.rb +73 -0
- data/lib/csv_decision/table.rb +24 -18
- data/lib/csv_decision.rb +25 -18
- data/spec/csv_decision/columns_spec.rb +1 -1
- data/spec/csv_decision/constant_spec.rb +60 -0
- data/spec/csv_decision/examples_spec.rb +119 -0
- data/spec/csv_decision/matchers/function_spec.rb +48 -28
- data/spec/csv_decision/matchers/numeric_spec.rb +4 -41
- data/spec/csv_decision/matchers/range_spec.rb +31 -61
- data/spec/csv_decision/matchers/symbol_spec.rb +65 -0
- data/spec/csv_decision/options_spec.rb +14 -2
- data/spec/csv_decision/parse_spec.rb +10 -0
- data/spec/csv_decision/table_spec.rb +112 -6
- data/spec/data/valid/simple_constants.csv +3 -3
- metadata +62 -7
- data/spec/csv_decision/simple_example_spec.rb +0 -75
- /data/spec/{csv_decision.rb → csv_decision_spec.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ae0f8b7985c3403c552bac2d32f6d6dbcf72046
|
4
|
+
data.tar.gz: 447fc311c43a0ed399866f8a032b4abd56583790
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e0bac50f203c9c4403894da74f853885792f0d4d80a09e8452c89bf98af7390a1d89b220fe03b65bf4ca0b8a2f88ca6b76797833a922920967071abc7b36bb4
|
7
|
+
data.tar.gz: f1f479e5d022cad346d50dfcfdd73093dadc14df906ca8cc09574a5fb5b4c8cdf89f354b9750d3468f01fb5c63e82394d9f7a2118f054a74e8460f69289a7550
|
data/.codeclimate.yml
ADDED
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,2 +1,20 @@
|
|
1
|
-
## v0.0.
|
1
|
+
## v0.0.4, 26 December 2017.
|
2
|
+
*Additions*
|
3
|
+
- Adds symbol expressions for input columns.
|
4
|
+
- Adds non-string constants for output columns.
|
5
|
+
- Support Ruby 2.5.0
|
6
|
+
- Include yard documentation.
|
7
|
+
|
8
|
+
*Changes*
|
9
|
+
- Move `benchmark.rb` to `benchmarks` folder and rename to `rufus_decision.rb`
|
10
|
+
|
11
|
+
## v0.0.3, 18 December 2017.
|
12
|
+
*Additions*
|
13
|
+
- Add non-string constants for input columns.
|
14
|
+
|
15
|
+
## v0.0.2, 18 December 2017.
|
16
|
+
*Additions*
|
17
|
+
- Adds accumulate option.
|
18
|
+
|
19
|
+
## v0.0.1, 18 December 2017.
|
2
20
|
- Initial release
|
data/README.md
CHANGED
@@ -4,7 +4,8 @@ CSV Decision
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/csv_decision.svg)](https://badge.fury.io/rb/csv_decision)
|
5
5
|
[![Build Status](https://travis-ci.org/bpvickers/csv_decision.svg?branch=master)](https://travis-ci.org/bpvickers/csv_decision)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/github/bpvickers/csv_decision/badge.svg?branch=master)](https://coveralls.io/github/bpvickers/csv_decision?branch=master)
|
7
|
-
|
7
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/466a6c52e8f6a3840967/maintainability)](https://codeclimate.com/github/bpvickers/csv_decision/maintainability)
|
8
|
+
[![License](http://img.shields.io/badge/license-MIT-yellowgreen.svg)](#license)
|
8
9
|
|
9
10
|
### CSV based Ruby decision tables (a lightweight Hash transformation gem)
|
10
11
|
|
@@ -15,10 +16,11 @@ It accepts decision tables implemented as a
|
|
15
16
|
which can then be used to execute complex conditional logic against an input hash,
|
16
17
|
producing a decision as an output hash.
|
17
18
|
|
18
|
-
###
|
19
|
+
### CSV Decision features
|
19
20
|
* Fast decision-time performance (see `benchmark.rb`).
|
20
|
-
* In addition to simple string matching, can
|
21
|
-
numeric comparisons and Ruby-style ranges.
|
21
|
+
* In addition to simple string matching, can match common Ruby constants,
|
22
|
+
regular expressions, numeric comparisons and Ruby-style ranges.
|
23
|
+
* Can use column symbols in comparisons for guard conditions -- e.g., > :column.
|
22
24
|
* Accepts data as a file, CSV string or an array of arrays. (For safety all input data is
|
23
25
|
force encoded to UTF-8, and non-ascii strings are converted to empty strings.)
|
24
26
|
* All CSV cells are parsed for correctness, and helpful error messages generated for bad
|
@@ -27,14 +29,14 @@ producing a decision as an output hash.
|
|
27
29
|
array of hashes.
|
28
30
|
|
29
31
|
### Planned features
|
30
|
-
`csv_decision` is
|
32
|
+
`csv_decision` is still a work in progress, and will be enhanced to support
|
31
33
|
the following features:
|
32
34
|
* Input columns may be indexed for faster lookup performance.
|
33
35
|
* May use functions in the output columns to formulate the final decision.
|
34
36
|
* Input hash values may be conditionally defaulted using a constant or a function call
|
35
37
|
* Use of column symbol references or built-in guard functions in the input
|
36
38
|
columns for matching.
|
37
|
-
* Output columns may
|
39
|
+
* Output columns may use interpolated strings referencing column symbols.
|
38
40
|
* May be extended with user-defined Ruby functions for tailored logic.
|
39
41
|
* Can use post-match guard conditions to filter the results of multi-row
|
40
42
|
decision output.
|
@@ -149,7 +151,7 @@ table.decide(topic: 'finance', region: 'Europe') # returns team_member: %w[Donal
|
|
149
151
|
### Constants other than strings
|
150
152
|
Although `csv_decision` is string oriented, it does recognise other types of constant
|
151
153
|
present in the input hash. Specifically, the following classes are recognized:
|
152
|
-
`Integer`, `BigDecimal` and `
|
154
|
+
`Integer`, `BigDecimal`, `NilClass`, `TrueClass` and `FalseClass`.
|
153
155
|
|
154
156
|
This is accomplished by prefixing the value with one of the operators `=`, `==` or `:=`.
|
155
157
|
(The syntax is intentionally lax.)
|
@@ -157,20 +159,51 @@ table.decide(topic: 'finance', region: 'Europe') # returns team_member: %w[Donal
|
|
157
159
|
For example:
|
158
160
|
```ruby
|
159
161
|
data = <<~DATA
|
160
|
-
in :constant, out :
|
161
|
-
:=nil,
|
162
|
-
==false,
|
163
|
-
=true,
|
164
|
-
= 0,
|
165
|
-
:=100.0, 100
|
162
|
+
in :constant, out :value
|
163
|
+
:=nil, :=nil
|
164
|
+
==false, ==false
|
165
|
+
=true, =true
|
166
|
+
= 0, = 0
|
167
|
+
:=100.0, :=100.0
|
166
168
|
DATA
|
167
169
|
|
168
170
|
table = CSVDecision.parse(data)
|
169
|
-
table.decide(constant: nil) # returns
|
170
|
-
table.decide(constant: 0) # returns
|
171
|
-
table.decide(constant: BigDecimal
|
171
|
+
table.decide(constant: nil) # returns value: nil
|
172
|
+
table.decide(constant: 0) # returns value: 0
|
173
|
+
table.decide(constant: BigDecimal('100.0')) # returns value: BigDecimal('100.0')
|
172
174
|
```
|
173
175
|
|
176
|
+
### Column header symbols
|
177
|
+
All input and output column names are symbolized, and can be used to form simple
|
178
|
+
expressions that refer to values in the input hash.
|
179
|
+
|
180
|
+
For example:
|
181
|
+
```ruby
|
182
|
+
data = <<~DATA
|
183
|
+
in :node, in :parent, out :top?
|
184
|
+
, == :node, yes
|
185
|
+
, , no
|
186
|
+
DATA
|
187
|
+
|
188
|
+
table = CSVDecision.parse(data)
|
189
|
+
table.decide(node: 0, parent: 0) # returns top?: 'yes'
|
190
|
+
table.decide(node: 1, parent: 0) # returns top?: 'no'
|
191
|
+
```
|
192
|
+
|
193
|
+
Note that there is no need to include an input column for `:node` in the decision
|
194
|
+
table - it just needs to be present in the input hash. Also, `== :node` can be
|
195
|
+
shortened to just `:node`, so the above decision table may be simplified to:
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
data = <<~DATA
|
199
|
+
in :parent, out :top?
|
200
|
+
:node, yes
|
201
|
+
, no
|
202
|
+
DATA
|
203
|
+
```
|
204
|
+
These comparison operators are also supported: `!=`, `>`, `>=`, `<`, `<=`.
|
205
|
+
For more simple examples see `spec/csv_decision/examples_spec.rb`.
|
206
|
+
|
174
207
|
### Testing
|
175
208
|
|
176
209
|
`csv_decision` includes thorough [RSpec](http://rspec.info) tests:
|
data/csv_decision.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'csv_decision'
|
8
|
-
spec.version = '0.0.
|
8
|
+
spec.version = '0.0.4'
|
9
9
|
spec.authors = ['Brett Vickers']
|
10
10
|
spec.email = ['brett@phillips-vickers.com']
|
11
11
|
spec.description = 'CSV based Ruby decision tables.'
|
@@ -0,0 +1,143 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Exception: CSVDecision::CellValidationError
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.12
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "CSVDecision::CellValidationError";
|
19
|
+
relpath = '../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
+
|
27
|
+
|
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>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../_index.html">Index (C)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../CSVDecision.html" title="CSVDecision (module)">CSVDecision</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">CellValidationError</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Exception: CSVDecision::CellValidationError
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
<dl>
|
70
|
+
<dt>Inherits:</dt>
|
71
|
+
<dd>
|
72
|
+
<span class="inheritName"><span class='object_link'><a href="Error.html" title="CSVDecision::Error (class)">Error</a></span></span>
|
73
|
+
|
74
|
+
<ul class="fullTree">
|
75
|
+
<li>Object</li>
|
76
|
+
|
77
|
+
<li class="next">StandardError</li>
|
78
|
+
|
79
|
+
<li class="next"><span class='object_link'><a href="Error.html" title="CSVDecision::Error (class)">Error</a></span></li>
|
80
|
+
|
81
|
+
<li class="next">CSVDecision::CellValidationError</li>
|
82
|
+
|
83
|
+
</ul>
|
84
|
+
<a href="#" class="inheritanceTree">show all</a>
|
85
|
+
|
86
|
+
</dd>
|
87
|
+
</dl>
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
<dl>
|
100
|
+
<dt>Defined in:</dt>
|
101
|
+
<dd>lib/csv_decision/parse.rb</dd>
|
102
|
+
</dl>
|
103
|
+
|
104
|
+
</div>
|
105
|
+
|
106
|
+
<h2>Overview</h2><div class="docstring">
|
107
|
+
<div class="discussion">
|
108
|
+
|
109
|
+
<p>Error validating a cell when parsing input table data.</p>
|
110
|
+
|
111
|
+
|
112
|
+
</div>
|
113
|
+
</div>
|
114
|
+
<div class="tags">
|
115
|
+
|
116
|
+
|
117
|
+
</div>
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
</div>
|
134
|
+
|
135
|
+
<div id="footer">
|
136
|
+
Generated on Tue Dec 26 18:31:37 2017 by
|
137
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
138
|
+
0.9.12 (ruby-2.3.0).
|
139
|
+
</div>
|
140
|
+
|
141
|
+
</div>
|
142
|
+
</body>
|
143
|
+
</html>
|