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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative '../../lib/
|
|
3
|
+
require_relative '../../lib/csv_decision2'
|
|
4
4
|
|
|
5
|
-
SPEC_DATA_VALID ||= File.join(
|
|
5
|
+
SPEC_DATA_VALID ||= File.join(CSVDecision2.root, 'spec', 'data', 'valid')
|
|
6
6
|
|
|
7
|
-
describe
|
|
7
|
+
describe CSVDecision2::Table do
|
|
8
8
|
describe '#decide' do
|
|
9
9
|
context 'makes correct decisions for simple, text-only tables' do
|
|
10
10
|
examples = [
|
|
@@ -34,7 +34,7 @@ describe CSVDecision::Table do
|
|
|
34
34
|
%i[decide decide!].each do |method|
|
|
35
35
|
it "#{method} correctly #{test[:example]} with first_match: true" do
|
|
36
36
|
options = test[:options].merge(first_match: true)
|
|
37
|
-
table =
|
|
37
|
+
table = CSVDecision2.parse(test[:data], options)
|
|
38
38
|
|
|
39
39
|
expect(table.send(method, topic: 'finance', region: 'Europe')).to eq(team_member: 'Donald')
|
|
40
40
|
expect(table.send(method, topic: 'sports', region: nil)).to eq(team_member: 'Bob')
|
|
@@ -43,7 +43,7 @@ describe CSVDecision::Table do
|
|
|
43
43
|
|
|
44
44
|
it "#{method} correctly #{test[:example]} with first_match: false" do
|
|
45
45
|
options = test[:options].merge(first_match: false)
|
|
46
|
-
table =
|
|
46
|
+
table = CSVDecision2.parse(test[:data], options)
|
|
47
47
|
|
|
48
48
|
expect(table.send(method, topic: 'finance', region: 'Europe'))
|
|
49
49
|
.to eq(team_member: %w[Donald Ernest Zach])
|
|
@@ -79,7 +79,7 @@ describe CSVDecision::Table do
|
|
|
79
79
|
%i[decide decide!].each do |method|
|
|
80
80
|
it "#{method} correctly #{test[:example]} with first_match: true" do
|
|
81
81
|
options = test[:options].merge(first_match: true)
|
|
82
|
-
table =
|
|
82
|
+
table = CSVDecision2.parse(test[:data], options)
|
|
83
83
|
|
|
84
84
|
expect(table.send(method, constant: nil)).to eq(type: nil)
|
|
85
85
|
expect(table.send(method, constant: 0)).to eq(type: 0)
|
|
@@ -168,7 +168,7 @@ describe CSVDecision::Table do
|
|
|
168
168
|
%i[decide decide!].each do |method|
|
|
169
169
|
it "#{method} correctly uses #{test[:example]} with first_match: true" do
|
|
170
170
|
options = test[:options].merge(first_match: true)
|
|
171
|
-
table =
|
|
171
|
+
table = CSVDecision2.parse(test[:data], options)
|
|
172
172
|
|
|
173
173
|
expect(table.send(method, age: 100)).to eq(salesperson: 'Thorsten')
|
|
174
174
|
expect(table.send(method, age: 25, trait: 'very rich')).to eq(salesperson: 'Kerfelden')
|
|
@@ -182,7 +182,7 @@ describe CSVDecision::Table do
|
|
|
182
182
|
|
|
183
183
|
it "#{method} correctly uses #{test[:example]} with first_match: false" do
|
|
184
184
|
options = test[:options].merge(first_match: false)
|
|
185
|
-
table =
|
|
185
|
+
table = CSVDecision2.parse(test[:data], options)
|
|
186
186
|
|
|
187
187
|
expect(table.send(method, age: 100))
|
|
188
188
|
.to eq(salesperson: %w[Thorsten Ojiisan])
|
|
@@ -284,7 +284,7 @@ describe CSVDecision::Table do
|
|
|
284
284
|
%i[decide decide!].each do |method|
|
|
285
285
|
it "#{method} correctly #{test[:example]}" do
|
|
286
286
|
options = test[:options]
|
|
287
|
-
table =
|
|
287
|
+
table = CSVDecision2.parse(test[:data], options)
|
|
288
288
|
|
|
289
289
|
expect(table.send(method, node: 0, parent: 0)).to eq(top?: 'yes')
|
|
290
290
|
expect(table.send(method, node: 1, parent: 0)).to eq(top?: 'no')
|
|
@@ -320,7 +320,7 @@ describe CSVDecision::Table do
|
|
|
320
320
|
examples.each do |test|
|
|
321
321
|
%i[decide decide!].each do |method|
|
|
322
322
|
it "#{method} correctly #{test[:example]}" do
|
|
323
|
-
table =
|
|
323
|
+
table = CSVDecision2.parse(test[:data], test[:options])
|
|
324
324
|
|
|
325
325
|
expect(table.send(method, traded: '20171227', settled: '20171227')).to eq(status: 'same day')
|
|
326
326
|
expect(table.send(method, traded: 20171227, settled: 20171227 )).to eq(status: 'same day')
|
|
@@ -388,7 +388,7 @@ describe CSVDecision::Table do
|
|
|
388
388
|
examples.each do |test|
|
|
389
389
|
%i[decide decide!].each do |method|
|
|
390
390
|
it "#{method} correctly #{test[:example]}" do
|
|
391
|
-
table =
|
|
391
|
+
table = CSVDecision2.parse(test[:data], test[:options])
|
|
392
392
|
|
|
393
393
|
expect(table.send(method, country: 'US', CUSIP: '123456789'))
|
|
394
394
|
.to eq(PAID: '123456789', PAID_type: 'CUSIP', len: 9)
|
|
@@ -437,7 +437,7 @@ describe CSVDecision::Table do
|
|
|
437
437
|
examples.each do |test|
|
|
438
438
|
%i[decide decide!].each do |method|
|
|
439
439
|
it "#{method} correctly #{test[:example]}" do
|
|
440
|
-
table =
|
|
440
|
+
table = CSVDecision2.parse(test[:data], test[:options])
|
|
441
441
|
|
|
442
442
|
expect(table.send(method, country: 'US', CUSIP: '123456789', Ticker: 'USTY'))
|
|
443
443
|
.to eq(ID: '123456789', ID_type: 'CUSIP', len: 9)
|
|
@@ -480,7 +480,7 @@ describe CSVDecision::Table do
|
|
|
480
480
|
examples.each do |test|
|
|
481
481
|
%i[decide decide!].each do |method|
|
|
482
482
|
it "#{method} correctly #{test[:example]}" do
|
|
483
|
-
table =
|
|
483
|
+
table = CSVDecision2.parse(test[:data], test[:options])
|
|
484
484
|
|
|
485
485
|
expect(table.send(method, CUSIP: '1234567890', class: 'Private')).to eq(PAID: '1234567890', len: 10)
|
|
486
486
|
expect(table.send(method, CUSIP: '123456789', type: 'Equity', class: 'Public')).to eq(PAID: '123456789', len: 9)
|
|
@@ -519,7 +519,7 @@ describe CSVDecision::Table do
|
|
|
519
519
|
examples.each do |test|
|
|
520
520
|
%i[decide decide!].each do |method|
|
|
521
521
|
it "#{method} correctly #{test[:example]}" do
|
|
522
|
-
table =
|
|
522
|
+
table = CSVDecision2.parse(test[:data], test[:options])
|
|
523
523
|
|
|
524
524
|
expect(table.send(method, topic: 'politics', region: 'Arctic'))
|
|
525
525
|
.to eq(team_member: %w[Henry Zach])
|
|
@@ -582,7 +582,7 @@ describe CSVDecision::Table do
|
|
|
582
582
|
examples.each do |test|
|
|
583
583
|
%i[decide decide!].each do |method|
|
|
584
584
|
it "#{method} correctly #{test[:example]}" do
|
|
585
|
-
table =
|
|
585
|
+
table = CSVDecision2.parse(test[:data], test[:options])
|
|
586
586
|
|
|
587
587
|
expect(table.send(method, number: 1, type: 'integer', input: 'none')).to eq(output: 0)
|
|
588
588
|
expect(table.send(method, number: nil, type: 'string', input: 'one')).to eq(output: nil)
|
|
@@ -600,7 +600,7 @@ describe CSVDecision::Table do
|
|
|
600
600
|
payload, , !nil?, :type_cd, :value.present?
|
|
601
601
|
payload, ref_data, , :type_id, :value.present?
|
|
602
602
|
DATA
|
|
603
|
-
table =
|
|
603
|
+
table = CSVDecision2.parse(data)
|
|
604
604
|
|
|
605
605
|
input = {
|
|
606
606
|
header: { id: 1, type_cd: 'BUY' },
|
|
@@ -646,7 +646,7 @@ describe CSVDecision::Table do
|
|
|
646
646
|
payload, ref_data, :account_id, account_id, :value.present?
|
|
647
647
|
header, metrics, :receive_time, receive_tm, :value.present?
|
|
648
648
|
DATA
|
|
649
|
-
table =
|
|
649
|
+
table = CSVDecision2.parse(data, first_match: false)
|
|
650
650
|
|
|
651
651
|
input = {
|
|
652
652
|
header: {
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: csv_decision2
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Imamul Akhyar
|
|
@@ -228,50 +228,50 @@ files:
|
|
|
228
228
|
- doc/method_list.html
|
|
229
229
|
- doc/top-level-namespace.html
|
|
230
230
|
- docker-compose.yml
|
|
231
|
-
- lib/
|
|
232
|
-
- lib/
|
|
233
|
-
- lib/
|
|
234
|
-
- lib/
|
|
235
|
-
- lib/
|
|
236
|
-
- lib/
|
|
237
|
-
- lib/
|
|
238
|
-
- lib/
|
|
239
|
-
- lib/
|
|
240
|
-
- lib/
|
|
241
|
-
- lib/
|
|
242
|
-
- lib/
|
|
243
|
-
- lib/
|
|
244
|
-
- lib/
|
|
245
|
-
- lib/
|
|
246
|
-
- lib/
|
|
247
|
-
- lib/
|
|
248
|
-
- lib/
|
|
249
|
-
- lib/
|
|
250
|
-
- lib/
|
|
251
|
-
- lib/
|
|
252
|
-
- lib/
|
|
253
|
-
- lib/
|
|
254
|
-
- lib/
|
|
255
|
-
- lib/
|
|
256
|
-
- lib/
|
|
257
|
-
- spec/
|
|
258
|
-
- spec/
|
|
259
|
-
- spec/
|
|
260
|
-
- spec/
|
|
261
|
-
- spec/
|
|
262
|
-
- spec/
|
|
263
|
-
- spec/
|
|
264
|
-
- spec/
|
|
265
|
-
- spec/
|
|
266
|
-
- spec/
|
|
267
|
-
- spec/
|
|
268
|
-
- spec/
|
|
269
|
-
- spec/
|
|
270
|
-
- spec/
|
|
271
|
-
- spec/
|
|
272
|
-
- spec/
|
|
273
|
-
- spec/
|
|
274
|
-
- spec/
|
|
231
|
+
- lib/csv_decision2.rb
|
|
232
|
+
- lib/csv_decision2/columns.rb
|
|
233
|
+
- lib/csv_decision2/data.rb
|
|
234
|
+
- lib/csv_decision2/decision.rb
|
|
235
|
+
- lib/csv_decision2/defaults.rb
|
|
236
|
+
- lib/csv_decision2/dictionary.rb
|
|
237
|
+
- lib/csv_decision2/header.rb
|
|
238
|
+
- lib/csv_decision2/index.rb
|
|
239
|
+
- lib/csv_decision2/input.rb
|
|
240
|
+
- lib/csv_decision2/load.rb
|
|
241
|
+
- lib/csv_decision2/matchers.rb
|
|
242
|
+
- lib/csv_decision2/matchers/constant.rb
|
|
243
|
+
- lib/csv_decision2/matchers/function.rb
|
|
244
|
+
- lib/csv_decision2/matchers/guard.rb
|
|
245
|
+
- lib/csv_decision2/matchers/numeric.rb
|
|
246
|
+
- lib/csv_decision2/matchers/pattern.rb
|
|
247
|
+
- lib/csv_decision2/matchers/range.rb
|
|
248
|
+
- lib/csv_decision2/matchers/symbol.rb
|
|
249
|
+
- lib/csv_decision2/options.rb
|
|
250
|
+
- lib/csv_decision2/parse.rb
|
|
251
|
+
- lib/csv_decision2/paths.rb
|
|
252
|
+
- lib/csv_decision2/result.rb
|
|
253
|
+
- lib/csv_decision2/scan.rb
|
|
254
|
+
- lib/csv_decision2/scan_row.rb
|
|
255
|
+
- lib/csv_decision2/table.rb
|
|
256
|
+
- lib/csv_decision2/validate.rb
|
|
257
|
+
- spec/csv_decision2/columns_spec.rb
|
|
258
|
+
- spec/csv_decision2/constant_spec.rb
|
|
259
|
+
- spec/csv_decision2/data_spec.rb
|
|
260
|
+
- spec/csv_decision2/decision_spec.rb
|
|
261
|
+
- spec/csv_decision2/examples_spec.rb
|
|
262
|
+
- spec/csv_decision2/index_spec.rb
|
|
263
|
+
- spec/csv_decision2/input_spec.rb
|
|
264
|
+
- spec/csv_decision2/load_spec.rb
|
|
265
|
+
- spec/csv_decision2/matchers/function_spec.rb
|
|
266
|
+
- spec/csv_decision2/matchers/guard_spec.rb
|
|
267
|
+
- spec/csv_decision2/matchers/numeric_spec.rb
|
|
268
|
+
- spec/csv_decision2/matchers/pattern_spec.rb
|
|
269
|
+
- spec/csv_decision2/matchers/range_spec.rb
|
|
270
|
+
- spec/csv_decision2/matchers/symbol_spec.rb
|
|
271
|
+
- spec/csv_decision2/options_spec.rb
|
|
272
|
+
- spec/csv_decision2/parse_spec.rb
|
|
273
|
+
- spec/csv_decision2/table_spec.rb
|
|
274
|
+
- spec/csv_decision2_spec.rb
|
|
275
275
|
- spec/data/invalid/empty.csv
|
|
276
276
|
- spec/data/invalid/invalid_header1.csv
|
|
277
277
|
- spec/data/invalid/invalid_header2.csv
|
|
@@ -289,7 +289,7 @@ files:
|
|
|
289
289
|
- spec/data/valid/simple_example.csv
|
|
290
290
|
- spec/data/valid/valid.csv
|
|
291
291
|
- spec/spec_helper.rb
|
|
292
|
-
homepage: https://github.com/imamulakhyar93/
|
|
292
|
+
homepage: https://github.com/imamulakhyar93/csv_decision2.git
|
|
293
293
|
licenses:
|
|
294
294
|
- MIT
|
|
295
295
|
metadata: {}
|
|
@@ -315,24 +315,24 @@ summary: CSV Decision implements CSV based Ruby decision tables. It parses and l
|
|
|
315
315
|
decision table files which can then be used to execute complex conditional logic
|
|
316
316
|
against an input hash, producing a decision as an output hash.
|
|
317
317
|
test_files:
|
|
318
|
-
- spec/
|
|
319
|
-
- spec/
|
|
320
|
-
- spec/
|
|
321
|
-
- spec/
|
|
322
|
-
- spec/
|
|
323
|
-
- spec/
|
|
324
|
-
- spec/
|
|
325
|
-
- spec/
|
|
326
|
-
- spec/
|
|
327
|
-
- spec/
|
|
328
|
-
- spec/
|
|
329
|
-
- spec/
|
|
330
|
-
- spec/
|
|
331
|
-
- spec/
|
|
332
|
-
- spec/
|
|
333
|
-
- spec/
|
|
334
|
-
- spec/
|
|
335
|
-
- spec/
|
|
318
|
+
- spec/csv_decision2/columns_spec.rb
|
|
319
|
+
- spec/csv_decision2/constant_spec.rb
|
|
320
|
+
- spec/csv_decision2/data_spec.rb
|
|
321
|
+
- spec/csv_decision2/decision_spec.rb
|
|
322
|
+
- spec/csv_decision2/examples_spec.rb
|
|
323
|
+
- spec/csv_decision2/index_spec.rb
|
|
324
|
+
- spec/csv_decision2/input_spec.rb
|
|
325
|
+
- spec/csv_decision2/load_spec.rb
|
|
326
|
+
- spec/csv_decision2/matchers/function_spec.rb
|
|
327
|
+
- spec/csv_decision2/matchers/guard_spec.rb
|
|
328
|
+
- spec/csv_decision2/matchers/numeric_spec.rb
|
|
329
|
+
- spec/csv_decision2/matchers/pattern_spec.rb
|
|
330
|
+
- spec/csv_decision2/matchers/range_spec.rb
|
|
331
|
+
- spec/csv_decision2/matchers/symbol_spec.rb
|
|
332
|
+
- spec/csv_decision2/options_spec.rb
|
|
333
|
+
- spec/csv_decision2/parse_spec.rb
|
|
334
|
+
- spec/csv_decision2/table_spec.rb
|
|
335
|
+
- spec/csv_decision2_spec.rb
|
|
336
336
|
- spec/data/invalid/empty.csv
|
|
337
337
|
- spec/data/invalid/invalid_header1.csv
|
|
338
338
|
- spec/data/invalid/invalid_header2.csv
|
data/lib/csv_decision.rb
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'active_support/core_ext/object'
|
|
4
|
-
require 'csv_decision/parse'
|
|
5
|
-
|
|
6
|
-
# CSV Decision: CSV based Ruby decision tables.
|
|
7
|
-
# Created December 2017.
|
|
8
|
-
# @author Brett Vickers <brett@phillips-vickers.com>
|
|
9
|
-
# See LICENSE and README.md for details.
|
|
10
|
-
module CSVDecision
|
|
11
|
-
# @return [String] gem project's root directory
|
|
12
|
-
def self.root
|
|
13
|
-
File.dirname __dir__
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
autoload :Columns, 'csv_decision/columns'
|
|
17
|
-
autoload :Data, 'csv_decision/data'
|
|
18
|
-
autoload :Decision, 'csv_decision/decision'
|
|
19
|
-
autoload :Defaults, 'csv_decision/defaults'
|
|
20
|
-
autoload :Dictionary, 'csv_decision/dictionary'
|
|
21
|
-
autoload :Header, 'csv_decision/header'
|
|
22
|
-
autoload :Index, 'csv_decision/index'
|
|
23
|
-
autoload :Input, 'csv_decision/input'
|
|
24
|
-
autoload :Load, 'csv_decision/load'
|
|
25
|
-
autoload :Matchers, 'csv_decision/matchers'
|
|
26
|
-
autoload :Options, 'csv_decision/options'
|
|
27
|
-
autoload :Parse, 'csv_decision/parse'
|
|
28
|
-
autoload :Paths, 'csv_decision/paths'
|
|
29
|
-
autoload :Result, 'csv_decision/result'
|
|
30
|
-
autoload :Scan, 'csv_decision/scan'
|
|
31
|
-
autoload :ScanRow, 'csv_decision/scan_row'
|
|
32
|
-
autoload :Table, 'csv_decision/table'
|
|
33
|
-
autoload :Validate, 'csv_decision/validate'
|
|
34
|
-
|
|
35
|
-
# Cell matchers
|
|
36
|
-
class Matchers
|
|
37
|
-
autoload :Constant, 'csv_decision/matchers/constant'
|
|
38
|
-
autoload :Function, 'csv_decision/matchers/function'
|
|
39
|
-
autoload :Guard, 'csv_decision/matchers/guard'
|
|
40
|
-
autoload :Numeric, 'csv_decision/matchers/numeric'
|
|
41
|
-
autoload :Pattern, 'csv_decision/matchers/pattern'
|
|
42
|
-
autoload :Range, 'csv_decision/matchers/range'
|
|
43
|
-
autoload :Symbol, 'csv_decision/matchers/symbol'
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../../lib/csv_decision'
|
|
4
|
-
|
|
5
|
-
describe CSVDecision::Parse do
|
|
6
|
-
it 'rejects an empty decision table' do
|
|
7
|
-
expect { CSVDecision.parse('') }
|
|
8
|
-
.to raise_error(CSVDecision::TableValidationError,
|
|
9
|
-
'table has no header row')
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it 'parses a decision table from a CSV file' do
|
|
13
|
-
file = Pathname(File.join(CSVDecision.root, 'spec/data/valid', 'valid.csv'))
|
|
14
|
-
result = CSVDecision.parse(file)
|
|
15
|
-
|
|
16
|
-
expected = [
|
|
17
|
-
['input', '']
|
|
18
|
-
]
|
|
19
|
-
|
|
20
|
-
expect(result).to be_a(CSVDecision::Table)
|
|
21
|
-
expect(result.rows).to eq expected
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
context 'it parses valid CSV files' do
|
|
25
|
-
Dir[File.join(CSVDecision.root, 'spec/data/valid/*.csv')].each do |file_name|
|
|
26
|
-
pathname = Pathname(file_name)
|
|
27
|
-
|
|
28
|
-
it "loads CSV file: #{pathname.basename}" do
|
|
29
|
-
expect { CSVDecision.parse(pathname) }.not_to raise_error
|
|
30
|
-
expect(CSVDecision.parse(pathname)).to be_a CSVDecision::Table
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context 'it rejects invalid CSV files' do
|
|
36
|
-
Dir[File.join(CSVDecision.root, 'spec/data/invalid/*.csv')].each do |file_name|
|
|
37
|
-
pathname = Pathname(file_name)
|
|
38
|
-
|
|
39
|
-
it "rejects CSV file: #{pathname.basename}" do
|
|
40
|
-
expect { CSVDecision.parse(pathname) }.to raise_error(CSVDecision::FileError)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|