csv_decision 0.0.3 → 0.0.4

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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -0
  3. data/.gitignore +2 -1
  4. data/.travis.yml +2 -3
  5. data/CHANGELOG.md +19 -1
  6. data/README.md +49 -16
  7. data/{benchmark.rb → benchmarks/rufus_decision.rb} +1 -1
  8. data/csv_decision.gemspec +1 -1
  9. data/doc/CSVDecision/CellValidationError.html +143 -0
  10. data/doc/CSVDecision/Columns/Default.html +409 -0
  11. data/doc/CSVDecision/Columns/Dictionary.html +410 -0
  12. data/doc/CSVDecision/Columns/Entry.html +321 -0
  13. data/doc/CSVDecision/Columns.html +476 -0
  14. data/doc/CSVDecision/Constant.html +295 -0
  15. data/doc/CSVDecision/Data.html +344 -0
  16. data/doc/CSVDecision/Decide.html +434 -0
  17. data/doc/CSVDecision/Decision.html +604 -0
  18. data/doc/CSVDecision/Error.html +139 -0
  19. data/doc/CSVDecision/FileError.html +143 -0
  20. data/doc/CSVDecision/Function.html +229 -0
  21. data/doc/CSVDecision/Header.html +520 -0
  22. data/doc/CSVDecision/Input.html +305 -0
  23. data/doc/CSVDecision/Load.html +225 -0
  24. data/doc/CSVDecision/Matchers/Constant.html +242 -0
  25. data/doc/CSVDecision/Matchers/Function.html +342 -0
  26. data/doc/CSVDecision/Matchers/Matcher.html +325 -0
  27. data/doc/CSVDecision/Matchers/Numeric.html +277 -0
  28. data/doc/CSVDecision/Matchers/Pattern.html +600 -0
  29. data/doc/CSVDecision/Matchers/Range.html +413 -0
  30. data/doc/CSVDecision/Matchers/Symbol.html +280 -0
  31. data/doc/CSVDecision/Matchers.html +1529 -0
  32. data/doc/CSVDecision/Numeric.html +259 -0
  33. data/doc/CSVDecision/Options.html +445 -0
  34. data/doc/CSVDecision/Parse.html +270 -0
  35. data/doc/CSVDecision/ScanRow.html +746 -0
  36. data/doc/CSVDecision/Symbol.html +256 -0
  37. data/doc/CSVDecision/Table.html +1115 -0
  38. data/doc/CSVDecision.html +652 -0
  39. data/doc/_index.html +410 -0
  40. data/doc/class_list.html +51 -0
  41. data/doc/css/common.css +1 -0
  42. data/doc/css/full_list.css +58 -0
  43. data/doc/css/style.css +499 -0
  44. data/doc/file.README.html +264 -0
  45. data/doc/file_list.html +56 -0
  46. data/doc/frames.html +17 -0
  47. data/doc/index.html +264 -0
  48. data/doc/js/app.js +248 -0
  49. data/doc/js/full_list.js +216 -0
  50. data/doc/js/jquery.js +4 -0
  51. data/doc/method_list.html +683 -0
  52. data/doc/top-level-namespace.html +110 -0
  53. data/lib/csv_decision/columns.rb +15 -12
  54. data/lib/csv_decision/constant.rb +54 -0
  55. data/lib/csv_decision/decide.rb +5 -5
  56. data/lib/csv_decision/decision.rb +3 -1
  57. data/lib/csv_decision/function.rb +32 -0
  58. data/lib/csv_decision/header.rb +27 -18
  59. data/lib/csv_decision/input.rb +11 -8
  60. data/lib/csv_decision/matchers/constant.rb +18 -0
  61. data/lib/csv_decision/matchers/function.rb +11 -44
  62. data/lib/csv_decision/matchers/numeric.rb +5 -33
  63. data/lib/csv_decision/matchers/pattern.rb +26 -11
  64. data/lib/csv_decision/matchers/range.rb +21 -5
  65. data/lib/csv_decision/matchers/symbol.rb +20 -0
  66. data/lib/csv_decision/matchers.rb +85 -20
  67. data/lib/csv_decision/numeric.rb +38 -0
  68. data/lib/csv_decision/options.rb +36 -27
  69. data/lib/csv_decision/parse.rb +46 -39
  70. data/lib/csv_decision/scan_row.rb +19 -7
  71. data/lib/csv_decision/symbol.rb +73 -0
  72. data/lib/csv_decision/table.rb +24 -18
  73. data/lib/csv_decision.rb +25 -18
  74. data/spec/csv_decision/columns_spec.rb +1 -1
  75. data/spec/csv_decision/constant_spec.rb +60 -0
  76. data/spec/csv_decision/examples_spec.rb +119 -0
  77. data/spec/csv_decision/matchers/function_spec.rb +48 -28
  78. data/spec/csv_decision/matchers/numeric_spec.rb +4 -41
  79. data/spec/csv_decision/matchers/range_spec.rb +31 -61
  80. data/spec/csv_decision/matchers/symbol_spec.rb +65 -0
  81. data/spec/csv_decision/options_spec.rb +14 -2
  82. data/spec/csv_decision/parse_spec.rb +10 -0
  83. data/spec/csv_decision/table_spec.rb +112 -6
  84. data/spec/data/valid/simple_constants.csv +3 -3
  85. metadata +62 -7
  86. data/spec/csv_decision/simple_example_spec.rb +0 -75
  87. /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: 5dd656bc42ac4a7e5bc1b3ba49599f972179fbe9
4
- data.tar.gz: 8f97105d30b993279dbadf380798fb4fbc36d4dd
3
+ metadata.gz: 0ae0f8b7985c3403c552bac2d32f6d6dbcf72046
4
+ data.tar.gz: 447fc311c43a0ed399866f8a032b4abd56583790
5
5
  SHA512:
6
- metadata.gz: d7c5bb91fcb110d0ef7a39def02096ae65e6cfc4eb1b9b17ad4e17407baa02004d5e835a7ce24df016b9b47683afebfeb37e632372447082e0229cb46174a6de
7
- data.tar.gz: bc3313687f8a01cdd82efdd59190bea881a4707382a23275c20b192b2d048db747a3200163e0b773c31fe9a500269484c10d990d363c9f75956df956ff1379c8
6
+ metadata.gz: 2e0bac50f203c9c4403894da74f853885792f0d4d80a09e8452c89bf98af7390a1d89b220fe03b65bf4ca0b8a2f88ca6b76797833a922920967071abc7b36bb4
7
+ data.tar.gz: f1f479e5d022cad346d50dfcfdd73093dadc14df906ca8cc09574a5fb5b4c8cdf89f354b9750d3468f01fb5c63e82394d9f7a2118f054a74e8460f69289a7550
data/.codeclimate.yml ADDED
@@ -0,0 +1,2 @@
1
+ exclude_patterns:
2
+ - "doc/"
data/.gitignore CHANGED
@@ -10,4 +10,5 @@ pkg/*
10
10
  # IDE files
11
11
  .idea
12
12
  .DS_Store
13
- coverage/
13
+ coverage/
14
+ .yardoc/
data/.travis.yml CHANGED
@@ -1,10 +1,9 @@
1
- env:
2
- global:
3
- - CC_TEST_REPORTER_ID=787a2f89b15c637323c7340d65ec17e898ac44480706b4b4122ea040c2a88f1d
4
1
  language: ruby
2
+ sudo: false
5
3
  rvm:
6
4
  - 2.3.0
7
5
  - 2.3.6
8
6
  - 2.4.3
7
+ - 2.5.0
9
8
  script:
10
9
  - bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -1,2 +1,20 @@
1
- ## v0.0.1, 28 December 2017.
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
- <a href="https://codeclimate.com/github/bpvickers/csv_decision/maintainability"><img src="https://api.codeclimate.com/v1/badges/466a6c52e8f6a3840967/maintainability" /></a>
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
- ### `csv_decision` features
19
+ ### CSV Decision features
19
20
  * Fast decision-time performance (see `benchmark.rb`).
20
- * In addition to simple string matching, can use regular expressions,
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 currently a work in progress, and will be enhanced to support
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 used interpolated strings referencing column symbols.
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 `NilClass`.
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 :type
161
- :=nil, NilClass
162
- ==false, FALSE
163
- =true, TRUE
164
- = 0, Zero
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 type: 'NilClass'
170
- table.decide(constant: 0) # returns type: 'Zero'
171
- table.decide(constant: BigDecimal.new('100.0')) # returns type: '100%'
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:
@@ -6,7 +6,7 @@ require 'rufus/decision'
6
6
  require 'ice_nine'
7
7
  require 'ice_nine/core_ext/object'
8
8
 
9
- require_relative 'lib/csv_decision'
9
+ require_relative '../lib/csv_decision'
10
10
 
11
11
  SPEC_DATA_VALID ||= File.join(CSVDecision.root, 'spec', 'data', 'valid')
12
12
 
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.3'
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
+ &mdash; 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> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../CSVDecision.html" title="CSVDecision (module)">CSVDecision</a></span></span>
41
+ &raquo;
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>