csv_decision 0.0.6 → 0.0.7
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/CHANGELOG.md +9 -1
- data/README.md +112 -93
- data/benchmarks/rufus_decision.rb +9 -1
- data/csv_decision.gemspec +6 -6
- data/doc/CSVDecision.html +54 -90
- data/doc/CSVDecision/CellValidationError.html +1 -1
- data/doc/CSVDecision/Columns.html +104 -45
- data/doc/CSVDecision/Columns/Dictionary.html +40 -24
- data/doc/CSVDecision/Columns/Entry.html +209 -22
- data/doc/CSVDecision/Constant.html +9 -50
- data/doc/CSVDecision/Data.html +182 -47
- data/doc/CSVDecision/Decide.html +97 -93
- data/doc/CSVDecision/Decision.html +105 -294
- data/doc/CSVDecision/Error.html +1 -1
- data/doc/CSVDecision/FileError.html +1 -1
- data/doc/CSVDecision/Function.html +18 -7
- data/doc/CSVDecision/Guard.html +245 -0
- data/doc/CSVDecision/Header.html +58 -50
- data/doc/CSVDecision/Input.html +20 -12
- data/doc/CSVDecision/Load.html +80 -14
- data/doc/CSVDecision/Matchers.html +237 -279
- data/doc/CSVDecision/Matchers/Constant.html +280 -13
- data/doc/CSVDecision/Matchers/Function.html +188 -19
- data/doc/CSVDecision/Matchers/Guard.html +568 -0
- data/doc/CSVDecision/Matchers/Matcher.html +200 -14
- data/doc/CSVDecision/Matchers/Numeric.html +165 -13
- data/doc/CSVDecision/Matchers/Pattern.html +56 -163
- data/doc/CSVDecision/Matchers/Range.html +48 -37
- data/doc/CSVDecision/Matchers/Symbol.html +161 -16
- data/doc/CSVDecision/Numeric.html +4 -4
- data/doc/CSVDecision/Options.html +53 -55
- data/doc/CSVDecision/Parse.html +23 -13
- data/doc/CSVDecision/ScanRow.html +461 -73
- data/doc/CSVDecision/Symbol.html +4 -4
- data/doc/CSVDecision/Table.html +185 -79
- data/doc/_index.html +15 -28
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +105 -82
- data/doc/index.html +105 -82
- data/doc/method_list.html +137 -113
- data/doc/top-level-namespace.html +1 -1
- data/lib/csv_decision.rb +2 -5
- data/lib/csv_decision/columns.rb +14 -5
- data/lib/csv_decision/data.rb +24 -6
- data/lib/csv_decision/decide.rb +18 -20
- data/lib/csv_decision/decision.rb +106 -42
- data/lib/csv_decision/header.rb +44 -23
- data/lib/csv_decision/input.rb +4 -2
- data/lib/csv_decision/load.rb +7 -3
- data/lib/csv_decision/matchers.rb +49 -41
- data/lib/csv_decision/matchers/constant.rb +62 -4
- data/lib/csv_decision/matchers/function.rb +33 -2
- data/lib/csv_decision/matchers/guard.rb +143 -0
- data/lib/csv_decision/matchers/numeric.rb +34 -3
- data/lib/csv_decision/matchers/pattern.rb +11 -4
- data/lib/csv_decision/matchers/range.rb +34 -26
- data/lib/csv_decision/matchers/symbol.rb +71 -5
- data/lib/csv_decision/options.rb +31 -20
- data/lib/csv_decision/parse.rb +28 -9
- data/lib/csv_decision/scan_row.rb +79 -13
- data/lib/csv_decision/table.rb +34 -23
- data/spec/csv_decision/columns_spec.rb +32 -7
- data/spec/csv_decision/constant_spec.rb +2 -26
- data/spec/csv_decision/decision_spec.rb +0 -9
- data/spec/csv_decision/examples_spec.rb +33 -16
- data/spec/csv_decision/matchers/function_spec.rb +1 -1
- data/spec/csv_decision/matchers/guard_spec.rb +153 -0
- data/spec/csv_decision/matchers/numeric_spec.rb +1 -1
- data/spec/csv_decision/matchers/pattern_spec.rb +2 -2
- data/spec/csv_decision/matchers/range_spec.rb +2 -2
- data/spec/csv_decision/matchers/symbol_spec.rb +1 -1
- data/spec/csv_decision/options_spec.rb +3 -3
- data/spec/csv_decision/table_spec.rb +96 -12
- data/spec/data/valid/benchmark_regexp.csv +10 -0
- data/spec/data/valid/regular_expressions.csv +11 -0
- metadata +14 -9
- data/lib/csv_decision/constant.rb +0 -54
- data/lib/csv_decision/function.rb +0 -32
- data/lib/csv_decision/numeric.rb +0 -38
- data/lib/csv_decision/symbol.rb +0 -73
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 076055f3dd0219da9a4d8aa3d0032fd26e320741
|
|
4
|
+
data.tar.gz: 7ed7716a9f1285b7ed86e3134321e08c829ae7e5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b87561c15e01daca109a562f68628b15b6f5d33a725ee527a10ad74d79733e5ffe7a8495735d8a41f18a930a4d906312f566a3c5d22fad182b9d94621a7c141d
|
|
7
|
+
data.tar.gz: be6922a755c26fea0b3d416ee75729bf76eec40a66d386d664aa4e3944be8f311f95d0bdfb004a314da049e2ebe5f0b39987752ccfbe446f01529f7fd62281ba
|
data/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
## v0.0.6, 26 December 2017.
|
|
2
|
+
*Additions*
|
|
3
|
+
- Update YARD documentation.
|
|
4
|
+
|
|
5
|
+
## v0.0.5, 26 December 2017.
|
|
6
|
+
*Additions*
|
|
7
|
+
- Update YARD documentation.
|
|
8
|
+
|
|
1
9
|
## v0.0.4, 26 December 2017.
|
|
2
10
|
*Additions*
|
|
3
11
|
- Adds symbol expressions for input columns.
|
|
4
12
|
- Adds non-string constants for output columns.
|
|
5
13
|
- Support Ruby 2.5.0
|
|
6
|
-
- Include
|
|
14
|
+
- Include YARD documentation.
|
|
7
15
|
|
|
8
16
|
*Changes*
|
|
9
17
|
- Move `benchmark.rb` to `benchmarks` folder and rename to `rufus_decision.rb`
|
data/README.md
CHANGED
|
@@ -7,7 +7,7 @@ CSV Decision
|
|
|
7
7
|
[](https://codeclimate.com/github/bpvickers/csv_decision/maintainability)
|
|
8
8
|
[](#license)
|
|
9
9
|
|
|
10
|
-
### CSV based Ruby decision tables
|
|
10
|
+
### CSV based Ruby decision tables
|
|
11
11
|
|
|
12
12
|
`csv_decision` is a RubyGem for CSV (comma separated values) based
|
|
13
13
|
[decision tables](https://en.wikipedia.org/wiki/Decision_table).
|
|
@@ -16,47 +16,24 @@ It accepts decision tables implemented as a
|
|
|
16
16
|
which can then be used to execute complex conditional logic against an input hash,
|
|
17
17
|
producing a decision as an output hash.
|
|
18
18
|
|
|
19
|
-
###
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
`
|
|
33
|
-
the following features:
|
|
34
|
-
* Input columns may be indexed for faster lookup performance.
|
|
35
|
-
* May use functions in the output columns to formulate the final decision.
|
|
36
|
-
* Input hash values may be conditionally defaulted using a constant or a function call
|
|
37
|
-
* Use of column symbol references or built-in guard functions in the input
|
|
38
|
-
columns for matching.
|
|
39
|
-
* Output columns may use interpolated strings referencing column symbols.
|
|
40
|
-
* May be extended with user-defined Ruby functions for tailored logic.
|
|
41
|
-
* Can use post-match guard conditions to filter the results of multi-row
|
|
42
|
-
decision output.
|
|
43
|
-
|
|
44
|
-
### Why use `csv_decision`?
|
|
45
|
-
|
|
46
|
-
Typical "business logic" is notoriously illogical -- full of corner cases and one-off
|
|
47
|
-
exceptions.
|
|
48
|
-
A decision table can capture data-based decisions in a way that comes more naturally
|
|
49
|
-
to subject matter experts, who typically prefer spreadsheet models.
|
|
50
|
-
Business logic may then be encapsulated, avoiding the need to write tortuous
|
|
51
|
-
conditional expressions in Ruby that draw the ire of `rubocop` and its ilk.
|
|
52
|
-
|
|
53
|
-
This gem takes its inspiration from
|
|
54
|
-
[rufus/decision](https://github.com/jmettraux/rufus-decision).
|
|
55
|
-
(That gem is no longer maintained and has issues with execution performance.)
|
|
19
|
+
### Why use `csv_decision`?
|
|
20
|
+
|
|
21
|
+
Typical "business logic" is notoriously illogical -- full of corner cases and one-off
|
|
22
|
+
exceptions.
|
|
23
|
+
A decision table can capture data-based decisions in a way that comes more naturally
|
|
24
|
+
to subject matter experts, who typically prefer spreadsheet models.
|
|
25
|
+
Business logic may then be encapsulated, avoiding the need to write tortuous
|
|
26
|
+
conditional expressions in Ruby that draw the ire of `rubocop` and its ilk.
|
|
27
|
+
|
|
28
|
+
This gem and the examples below take inspiration from
|
|
29
|
+
[rufus/decision](https://github.com/jmettraux/rufus-decision).
|
|
30
|
+
(However, that gem is no longer maintained and CSV Decision has better
|
|
31
|
+
decision-time performance for the trade-off of slower table parse times and more memory --
|
|
32
|
+
see `benchmarks/rufus_decision.rb`)
|
|
56
33
|
|
|
57
|
-
|
|
34
|
+
### Installation
|
|
58
35
|
|
|
59
|
-
|
|
36
|
+
To get started, just add `csv_decision` to your `Gemfile`, and then run `bundle`:
|
|
60
37
|
|
|
61
38
|
```ruby
|
|
62
39
|
gem 'csv_decision', '~> 0.0.1'
|
|
@@ -67,16 +44,11 @@ producing a decision as an output hash.
|
|
|
67
44
|
gem install csv_decision
|
|
68
45
|
```
|
|
69
46
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
https://jmettraux.wordpress.com/2009/04/25/rufus-decision-11-ruby-decision-tables/.
|
|
76
|
-
|
|
77
|
-
This example considers two input conditions: `topic` and `region`.
|
|
78
|
-
These are labeled `in`. Certain combinations yield an output value for `team_member`,
|
|
79
|
-
labeled `out`.
|
|
47
|
+
### Simple example
|
|
48
|
+
|
|
49
|
+
This table considers two input conditions: `topic` and `region`.
|
|
50
|
+
These are labeled `in`. Certain combinations yield an output value for `team_member`,
|
|
51
|
+
labeled `out`.
|
|
80
52
|
|
|
81
53
|
```
|
|
82
54
|
in :topic | in :region | out :team_member
|
|
@@ -92,18 +64,18 @@ politics | | Henry
|
|
|
92
64
|
| | Zach
|
|
93
65
|
```
|
|
94
66
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
67
|
+
When the topic is `finance` and the region is `Europe` the team member `Donald`
|
|
68
|
+
is selected.
|
|
69
|
+
|
|
70
|
+
This is a "first match" decision table in that as soon as a match is made execution
|
|
71
|
+
stops and a single output value (hash) is returned.
|
|
72
|
+
|
|
73
|
+
The ordering of rows matters. `Ernest`, who is in charge of `finance` for the rest of
|
|
74
|
+
the world, except for `America` and `Europe`, *must* come after his colleagues
|
|
75
|
+
`Charlie` and `Donald`. `Zach` has been placed last, catching all the input combos
|
|
76
|
+
not matching any other row.
|
|
77
|
+
|
|
78
|
+
Here it is as code:
|
|
107
79
|
|
|
108
80
|
```ruby
|
|
109
81
|
# Valid CSV string
|
|
@@ -127,36 +99,48 @@ politics | | Henry
|
|
|
127
99
|
table.decide(topic: 'culture', region: 'America') # team_member: 'Zach'
|
|
128
100
|
```
|
|
129
101
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
102
|
+
An empty `in` cell means "matches any value", even nils.
|
|
103
|
+
|
|
104
|
+
If you have cloned this gem's git repo, then the example can also be run by loading
|
|
105
|
+
the table from a CSV file:
|
|
134
106
|
|
|
135
107
|
```ruby
|
|
136
108
|
table = CSVDecision.parse(Pathname('spec/data/valid/simple_example.csv'))
|
|
137
109
|
```
|
|
138
110
|
|
|
139
|
-
We can also load this same table using the option: `first_match: false
|
|
111
|
+
We can also load this same table using the option: `first_match: false`, which means that
|
|
112
|
+
all matching rows will be accumulated into an array of hashes.
|
|
140
113
|
|
|
141
114
|
```ruby
|
|
142
115
|
table = CSVDecision.parse(data, first_match: false)
|
|
143
116
|
table.decide(topic: 'finance', region: 'Europe') # returns team_member: %w[Donald Ernest Zach]
|
|
144
117
|
```
|
|
145
118
|
|
|
119
|
+
For more examples see `spec/csv_decision/table_spec.rb`.
|
|
120
|
+
Complete documentation of all table parameters is in the code - see
|
|
121
|
+
`lib/csv_decision/parse.rb` and `lib/csv_decision/table.rb`.
|
|
146
122
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
123
|
+
### CSV Decision features
|
|
124
|
+
* Fast decision-time performance (see `benchmarks` folder).
|
|
125
|
+
* In addition to simple string matching, can match common Ruby constants,
|
|
126
|
+
regular expressions, numeric comparisons and Ruby-style ranges.
|
|
127
|
+
* Can use column symbols in comparisons for guard conditions -- e.g., > :column.
|
|
128
|
+
* Accepts data as a file, CSV string or an array of arrays. (For safety all input data is
|
|
129
|
+
force encoded to UTF-8, and non-ascii strings are converted to empty strings.)
|
|
130
|
+
* All CSV cells are parsed for correctness, and helpful error messages generated for bad
|
|
131
|
+
inputs.
|
|
132
|
+
* Either returns the first matching row as a hash, or accumulates all matches as an
|
|
133
|
+
array of hashes.
|
|
134
|
+
|
|
135
|
+
### Constants other than strings
|
|
136
|
+
Although `csv_decision` is string oriented, it does recognise other types of constant
|
|
137
|
+
present in the input hash. Specifically, the following classes are recognized:
|
|
138
|
+
`Integer`, `BigDecimal`, `NilClass`, `TrueClass` and `FalseClass`.
|
|
139
|
+
|
|
140
|
+
This is accomplished by prefixing the value with one of the operators `=`, `==` or `:=`.
|
|
141
|
+
(The syntax is intentionally lax.)
|
|
142
|
+
|
|
143
|
+
For example:
|
|
160
144
|
```ruby
|
|
161
145
|
data = <<~DATA
|
|
162
146
|
in :constant, out :value
|
|
@@ -173,11 +157,11 @@ table.decide(topic: 'finance', region: 'Europe') # returns team_member: %w[Donal
|
|
|
173
157
|
table.decide(constant: BigDecimal('100.0')) # returns value: BigDecimal('100.0')
|
|
174
158
|
```
|
|
175
159
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
160
|
+
### Column header symbols
|
|
161
|
+
All input and output column names are symbolized, and can be used to form simple
|
|
162
|
+
expressions that refer to values in the input hash.
|
|
163
|
+
|
|
164
|
+
For example:
|
|
181
165
|
```ruby
|
|
182
166
|
data = <<~DATA
|
|
183
167
|
in :node, in :parent, out :top?
|
|
@@ -190,10 +174,10 @@ table.decide(topic: 'finance', region: 'Europe') # returns team_member: %w[Donal
|
|
|
190
174
|
table.decide(node: 1, parent: 0) # returns top?: 'no'
|
|
191
175
|
```
|
|
192
176
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
177
|
+
Note that there is no need to include an input column for `:node` in the decision
|
|
178
|
+
table - it just needs to be present in the input hash. Also, `== :node` can be
|
|
179
|
+
shortened to just `:node`, so the above decision table may be simplified to:
|
|
180
|
+
|
|
197
181
|
```ruby
|
|
198
182
|
data = <<~DATA
|
|
199
183
|
in :parent, out :top?
|
|
@@ -201,10 +185,32 @@ table.decide(topic: 'finance', region: 'Europe') # returns team_member: %w[Donal
|
|
|
201
185
|
, no
|
|
202
186
|
DATA
|
|
203
187
|
```
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
188
|
+
These comparison operators are also supported: `!=`, `>`, `>=`, `<`, `<=`.
|
|
189
|
+
For more simple examples see `spec/csv_decision/examples_spec.rb`.
|
|
190
|
+
|
|
191
|
+
### Column guard conditions
|
|
192
|
+
Sometimes it's more convenient to write guard conditions in a single column specialized for that purpose.
|
|
193
|
+
For example:
|
|
194
|
+
|
|
195
|
+
```ruby
|
|
196
|
+
data = <<~DATA
|
|
197
|
+
in :country, guard:, out :ID, out :ID_type, out :len
|
|
198
|
+
US, :CUSIP.present?, :CUSIP, CUSIP, :ID.length
|
|
199
|
+
GB, :SEDOL.present?, :SEDOL, SEDOL, :ID.length
|
|
200
|
+
, :ISIN.present?, :ISIN, ISIN, :ID.length
|
|
201
|
+
, :SEDOL.present?, :SEDOL, SEDOL, :ID.length
|
|
202
|
+
, :CUSIP.present?, :CUSIP, CUSIP, :ID.length
|
|
203
|
+
, , := nil, := nil, := nil
|
|
204
|
+
DATA
|
|
205
|
+
|
|
206
|
+
table = CSVDecision.parse(data)
|
|
207
|
+
table.decide(country: 'US', CUSIP: '123456789') #=> { ID: '123456789', ID_type: 'CUSIP', len: 9 }
|
|
208
|
+
table.decide(country: 'EU', CUSIP: '123456789', ISIN:'123456789012')
|
|
209
|
+
#=> { ID: '123456789012', ID_type: 'ISIN', len: 12 }
|
|
210
|
+
```
|
|
211
|
+
Guard columns may be anonymous, and must contain non-constant expressions.
|
|
212
|
+
|
|
213
|
+
### Testing
|
|
208
214
|
|
|
209
215
|
`csv_decision` includes thorough [RSpec](http://rspec.info) tests:
|
|
210
216
|
|
|
@@ -213,3 +219,16 @@ table.decide(topic: 'finance', region: 'Europe') # returns team_member: %w[Donal
|
|
|
213
219
|
bundle install
|
|
214
220
|
rspec
|
|
215
221
|
```
|
|
222
|
+
|
|
223
|
+
### Planned features
|
|
224
|
+
`csv_decision` is still a work in progress, and will be enhanced to support
|
|
225
|
+
the following features:
|
|
226
|
+
* Use of column symbol expressions or built-in guard functions in the input
|
|
227
|
+
columns for matching.
|
|
228
|
+
* Input columns may be indexed for faster lookup performance.
|
|
229
|
+
* May use functions in the output columns to formulate the final decision.
|
|
230
|
+
* Input hash values may be conditionally defaulted using a constant or a function call
|
|
231
|
+
* Output columns may use interpolated strings referencing column symbols.
|
|
232
|
+
* May be extended with a user-supplied library of Ruby functions for tailored logic.
|
|
233
|
+
* Can use post-match guard conditions to filter the results of multi-row
|
|
234
|
+
decision output.
|
|
@@ -21,6 +21,14 @@ benchmarks = [
|
|
|
21
21
|
# Expected results for first_match and accumulate
|
|
22
22
|
first_match: { 'team_member' => 'Zach' },
|
|
23
23
|
accumulate: { 'team_member' => 'Zach' }
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'Regular expressions',
|
|
27
|
+
data: 'benchmark_regexp.csv',
|
|
28
|
+
input: { 'age' => '40', 'trait' => 'cheerful' },
|
|
29
|
+
# Expected results for first_match and accumulate
|
|
30
|
+
first_match: { 'salesperson' => 'Swanson' },
|
|
31
|
+
accumulate: { 'salesperson' => %w[Swanson Korolev] }
|
|
24
32
|
}
|
|
25
33
|
].deep_freeze
|
|
26
34
|
|
|
@@ -37,7 +45,7 @@ puts ""
|
|
|
37
45
|
puts '-' * tag_width
|
|
38
46
|
|
|
39
47
|
csv_options = CSV_OPTIONS.merge(first_match: first_match)
|
|
40
|
-
rufus_options = RUFUS_OPTIONS.merge(first_match: first_match)
|
|
48
|
+
rufus_options = RUFUS_OPTIONS.merge(first_match: first_match, accumulate: !first_match)
|
|
41
49
|
|
|
42
50
|
benchmarks.each do |test|
|
|
43
51
|
name = test[:name]
|
data/csv_decision.gemspec
CHANGED
|
@@ -5,14 +5,14 @@ $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.7'
|
|
9
9
|
spec.authors = ['Brett Vickers']
|
|
10
10
|
spec.email = ['brett@phillips-vickers.com']
|
|
11
11
|
spec.description = 'CSV based Ruby decision tables.'
|
|
12
12
|
spec.summary = <<-DESC
|
|
13
|
-
CSV Decision implements CSV
|
|
14
|
-
which can then be used to execute complex conditional
|
|
15
|
-
producing a decision as an output hash.
|
|
13
|
+
CSV Decision implements CSV based Ruby decision tables. It parses and loads
|
|
14
|
+
decision table files which can then be used to execute complex conditional
|
|
15
|
+
logic against an input hash, producing a decision as an output hash.
|
|
16
16
|
DESC
|
|
17
17
|
spec.homepage = 'https://github.com/bpvickers/csv_decision.git'
|
|
18
18
|
spec.license = 'MIT'
|
|
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
spec.required_ruby_version = '>= 2.3.0'
|
|
26
26
|
|
|
27
27
|
spec.add_dependency 'activesupport', '~> 5.1'
|
|
28
|
-
spec.add_dependency 'ice_nine',
|
|
29
|
-
spec.add_dependency 'values',
|
|
28
|
+
spec.add_dependency 'ice_nine', '~> 0.11'
|
|
29
|
+
spec.add_dependency 'values', '~> 1.8'
|
|
30
30
|
|
|
31
31
|
spec.add_development_dependency 'benchmark-ips', '~> 2.7'
|
|
32
32
|
spec.add_development_dependency 'benchmark-memory', '~> 0.1'
|
data/doc/CSVDecision.html
CHANGED
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
<dl>
|
|
80
80
|
<dt>Defined in:</dt>
|
|
81
81
|
<dd>lib/csv_decision.rb<span class="defines">,<br />
|
|
82
|
-
lib/csv_decision/data.rb,<br /> lib/csv_decision/load.rb,<br /> lib/csv_decision/input.rb,<br /> lib/csv_decision/parse.rb,<br /> lib/csv_decision/table.rb,<br /> lib/csv_decision/decide.rb,<br /> lib/csv_decision/header.rb,<br /> lib/csv_decision/
|
|
82
|
+
lib/csv_decision/data.rb,<br /> lib/csv_decision/load.rb,<br /> lib/csv_decision/input.rb,<br /> lib/csv_decision/parse.rb,<br /> lib/csv_decision/table.rb,<br /> lib/csv_decision/decide.rb,<br /> lib/csv_decision/header.rb,<br /> lib/csv_decision/columns.rb,<br /> lib/csv_decision/options.rb,<br /> lib/csv_decision/decision.rb,<br /> lib/csv_decision/matchers.rb,<br /> lib/csv_decision/scan_row.rb,<br /> lib/csv_decision/matchers/guard.rb,<br /> lib/csv_decision/matchers/range.rb,<br /> lib/csv_decision/matchers/symbol.rb,<br /> lib/csv_decision/matchers/numeric.rb,<br /> lib/csv_decision/matchers/pattern.rb,<br /> lib/csv_decision/matchers/constant.rb,<br /> lib/csv_decision/matchers/function.rb</span>
|
|
83
83
|
</dd>
|
|
84
84
|
</dl>
|
|
85
85
|
|
|
@@ -88,20 +88,36 @@
|
|
|
88
88
|
<h2>Overview</h2><div class="docstring">
|
|
89
89
|
<div class="discussion">
|
|
90
90
|
|
|
91
|
-
<p>CSV Decision: CSV based Ruby decision tables. Created December 2017
|
|
92
|
-
|
|
91
|
+
<p>CSV Decision: CSV based Ruby decision tables. Created December 2017. See
|
|
92
|
+
LICENSE and README.md for details.</p>
|
|
93
93
|
|
|
94
94
|
|
|
95
95
|
</div>
|
|
96
96
|
</div>
|
|
97
97
|
<div class="tags">
|
|
98
98
|
|
|
99
|
+
<p class="tag_title">Author:</p>
|
|
100
|
+
<ul class="author">
|
|
101
|
+
|
|
102
|
+
<li>
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
<div class='inline'>
|
|
109
|
+
<p>Brett Vickers <brett@phillips-vickers.com></p>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
</li>
|
|
113
|
+
|
|
114
|
+
</ul>
|
|
99
115
|
|
|
100
116
|
</div><h2>Defined Under Namespace</h2>
|
|
101
117
|
<p class="children">
|
|
102
118
|
|
|
103
119
|
|
|
104
|
-
<strong class="modules">Modules:</strong> <span class='object_link'><a href="CSVDecision/
|
|
120
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="CSVDecision/Data.html" title="CSVDecision::Data (module)">Data</a></span>, <span class='object_link'><a href="CSVDecision/Decide.html" title="CSVDecision::Decide (module)">Decide</a></span>, <span class='object_link'><a href="CSVDecision/Header.html" title="CSVDecision::Header (module)">Header</a></span>, <span class='object_link'><a href="CSVDecision/Input.html" title="CSVDecision::Input (module)">Input</a></span>, <span class='object_link'><a href="CSVDecision/Load.html" title="CSVDecision::Load (module)">Load</a></span>, <span class='object_link'><a href="CSVDecision/Options.html" title="CSVDecision::Options (module)">Options</a></span>, <span class='object_link'><a href="CSVDecision/Parse.html" title="CSVDecision::Parse (module)">Parse</a></span>
|
|
105
121
|
|
|
106
122
|
|
|
107
123
|
|
|
@@ -110,75 +126,6 @@ Brett Vickers See LICENSE and README.md for details.</p>
|
|
|
110
126
|
|
|
111
127
|
</p>
|
|
112
128
|
|
|
113
|
-
<h2>Constant Summary</h2>
|
|
114
|
-
<dl class="constants">
|
|
115
|
-
|
|
116
|
-
<dt id="COMMENT_CHARACTER-constant" class="">COMMENT_CHARACTER =
|
|
117
|
-
|
|
118
|
-
</dt>
|
|
119
|
-
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>#</span><span class='tstring_end'>'</span></span></pre></dd>
|
|
120
|
-
|
|
121
|
-
<dt id="DEFAULT_MATCHERS-constant" class="">DEFAULT_MATCHERS =
|
|
122
|
-
<div class="docstring">
|
|
123
|
-
<div class="discussion">
|
|
124
|
-
|
|
125
|
-
<p>Specialized cell value matchers beyond simple string compares. By default
|
|
126
|
-
all these matchers are tried in the specified order.</p>
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
</div>
|
|
130
|
-
</div>
|
|
131
|
-
<div class="tags">
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
</div>
|
|
135
|
-
</dt>
|
|
136
|
-
<dd><pre class="code"><span class='lbracket'>[</span>
|
|
137
|
-
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Range.html" title="CSVDecision::Matchers::Range (class)">Range</a></span></span><span class='comma'>,</span>
|
|
138
|
-
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Numeric.html" title="CSVDecision::Matchers::Numeric (class)">Numeric</a></span></span><span class='comma'>,</span>
|
|
139
|
-
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Pattern.html" title="CSVDecision::Matchers::Pattern (class)">Pattern</a></span></span><span class='comma'>,</span>
|
|
140
|
-
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Constant.html" title="CSVDecision::Matchers::Constant (class)">Constant</a></span></span><span class='comma'>,</span>
|
|
141
|
-
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Symbol.html" title="CSVDecision::Matchers::Symbol (class)">Symbol</a></span></span>
|
|
142
|
-
<span class='comment'># Matchers::Function
|
|
143
|
-
</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
|
|
144
|
-
|
|
145
|
-
<dt id="OUTS_MATCHERS-constant" class="">OUTS_MATCHERS =
|
|
146
|
-
<div class="docstring">
|
|
147
|
-
<div class="discussion">
|
|
148
|
-
|
|
149
|
-
<p>Subset of matchers that apply to output cells</p>
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
</div>
|
|
153
|
-
</div>
|
|
154
|
-
<div class="tags">
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
</div>
|
|
158
|
-
</dt>
|
|
159
|
-
<dd><pre class="code"><span class='lbracket'>[</span>
|
|
160
|
-
<span class='const'><span class='object_link'><a href="CSVDecision/Matchers.html" title="CSVDecision::Matchers (class)">Matchers</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="CSVDecision/Matchers/Constant.html" title="CSVDecision::Matchers::Constant (class)">Constant</a></span></span>
|
|
161
|
-
<span class='comment'># Matchers::Function
|
|
162
|
-
</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
|
|
163
|
-
|
|
164
|
-
<dt id="Proc-constant" class="">Proc =
|
|
165
|
-
<div class="docstring">
|
|
166
|
-
<div class="discussion">
|
|
167
|
-
|
|
168
|
-
<p>Value object for a cell proc.</p>
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
</div>
|
|
172
|
-
</div>
|
|
173
|
-
<div class="tags">
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
</div>
|
|
177
|
-
</dt>
|
|
178
|
-
<dd><pre class="code"><span class='const'>Value</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:type</span><span class='comma'>,</span> <span class='symbol'>:function</span><span class='rparen'>)</span></pre></dd>
|
|
179
|
-
|
|
180
|
-
</dl>
|
|
181
|
-
|
|
182
129
|
|
|
183
130
|
|
|
184
131
|
|
|
@@ -306,9 +253,8 @@ CSV string or an array of arrays.</p>
|
|
|
306
253
|
|
|
307
254
|
|
|
308
255
|
—
|
|
309
|
-
<div class='inline'
|
|
310
|
-
<p>
|
|
311
|
-
</li></ul>
|
|
256
|
+
<div class='inline'>
|
|
257
|
+
<p>Directory containing CSV files.</p>
|
|
312
258
|
</div>
|
|
313
259
|
|
|
314
260
|
</li>
|
|
@@ -325,9 +271,8 @@ CSV string or an array of arrays.</p>
|
|
|
325
271
|
|
|
326
272
|
|
|
327
273
|
—
|
|
328
|
-
<div class='inline'
|
|
329
|
-
<p>
|
|
330
|
-
</li></ul>
|
|
274
|
+
<div class='inline'>
|
|
275
|
+
<p>Options hash used for table creation.</p>
|
|
331
276
|
</div>
|
|
332
277
|
|
|
333
278
|
</li>
|
|
@@ -344,6 +289,24 @@ CSV string or an array of arrays.</p>
|
|
|
344
289
|
|
|
345
290
|
|
|
346
291
|
|
|
292
|
+
</li>
|
|
293
|
+
|
|
294
|
+
</ul>
|
|
295
|
+
<p class="tag_title">Raises:</p>
|
|
296
|
+
<ul class="raise">
|
|
297
|
+
|
|
298
|
+
<li>
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
—
|
|
306
|
+
<div class='inline'>
|
|
307
|
+
<p>Invalid folder.</p>
|
|
308
|
+
</div>
|
|
309
|
+
|
|
347
310
|
</li>
|
|
348
311
|
|
|
349
312
|
</ul>
|
|
@@ -354,12 +317,12 @@ CSV string or an array of arrays.</p>
|
|
|
354
317
|
<pre class="lines">
|
|
355
318
|
|
|
356
319
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
320
|
+
14
|
|
321
|
+
15
|
|
322
|
+
16</pre>
|
|
360
323
|
</td>
|
|
361
324
|
<td>
|
|
362
|
-
<pre class="code"><span class="info file"># File 'lib/csv_decision/load.rb', line
|
|
325
|
+
<pre class="code"><span class="info file"># File 'lib/csv_decision/load.rb', line 14</span>
|
|
363
326
|
|
|
364
327
|
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
|
365
328
|
<span class='const'><span class='object_link'><a href="CSVDecision/Load.html" title="CSVDecision::Load (module)">Load</a></span></span><span class='period'>.</span><span class='id identifier rubyid_path'><span class='object_link'><a href="CSVDecision/Load.html#path-class_method" title="CSVDecision::Load.path (method)">path</a></span></span><span class='lparen'>(</span><span class='label'>path:</span> <span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
|
@@ -398,7 +361,8 @@ CSV string or an array of arrays.</p>
|
|
|
398
361
|
</div></p>
|
|
399
362
|
|
|
400
363
|
<pre class="example code"><code>If you have cloned the gem's git repo, then you can run:
|
|
401
|
-
table = CSVDecision.parse(Pathname('spec/data/valid/simple_example.csv'))
|
|
364
|
+
table = CSVDecision.parse(Pathname('spec/data/valid/simple_example.csv'))
|
|
365
|
+
#=> CSVDecision::Table
|
|
402
366
|
table.decide(topic: 'finance', region: 'Europe') #=> team_member: 'Donald'</code></pre>
|
|
403
367
|
|
|
404
368
|
</div>
|
|
@@ -457,7 +421,7 @@ table.decide(topic: 'finance', region: 'Europe') #=> team_mem
|
|
|
457
421
|
</span>
|
|
458
422
|
|
|
459
423
|
— <div class='inline'>
|
|
460
|
-
<p>Stop scanning after
|
|
424
|
+
<p>Stop scanning after finding the first row match.</p>
|
|
461
425
|
</div>
|
|
462
426
|
|
|
463
427
|
</li>
|
|
@@ -563,12 +527,12 @@ table.decide(topic: 'finance', region: 'Europe') #=> team_mem
|
|
|
563
527
|
<pre class="lines">
|
|
564
528
|
|
|
565
529
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
530
|
+
46
|
|
531
|
+
47
|
|
532
|
+
48</pre>
|
|
569
533
|
</td>
|
|
570
534
|
<td>
|
|
571
|
-
<pre class="code"><span class="info file"># File 'lib/csv_decision/parse.rb', line
|
|
535
|
+
<pre class="code"><span class="info file"># File 'lib/csv_decision/parse.rb', line 46</span>
|
|
572
536
|
|
|
573
537
|
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
|
574
538
|
<span class='const'><span class='object_link'><a href="CSVDecision/Parse.html" title="CSVDecision::Parse (module)">Parse</a></span></span><span class='period'>.</span><span class='id identifier rubyid_table'><span class='object_link'><a href="CSVDecision/Parse.html#table-class_method" title="CSVDecision::Parse.table (method)">table</a></span></span><span class='lparen'>(</span><span class='label'>data:</span> <span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='label'>options:</span> <span class='const'><span class='object_link'><a href="CSVDecision/Options.html" title="CSVDecision::Options (module)">Options</a></span></span><span class='period'>.</span><span class='id identifier rubyid_normalize'><span class='object_link'><a href="CSVDecision/Options.html#normalize-class_method" title="CSVDecision::Options.normalize (method)">normalize</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
|
@@ -642,7 +606,7 @@ table.decide(topic: 'finance', region: 'Europe') #=> team_mem
|
|
|
642
606
|
</div>
|
|
643
607
|
|
|
644
608
|
<div id="footer">
|
|
645
|
-
Generated on
|
|
609
|
+
Generated on Sat Dec 30 13:04:04 2017 by
|
|
646
610
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
647
611
|
0.9.12 (ruby-2.3.0).
|
|
648
612
|
</div>
|