array_logic 0.2.3 → 0.2.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.
- data/README.rdoc +32 -19
- data/lib/array_logic.rb +1 -0
- data/lib/array_logic/exceptions.rb +6 -0
- data/lib/array_logic/rule.rb +3 -0
- data/lib/array_logic/version.rb +7 -1
- data/test/array_logic/rule_test.rb +14 -0
- metadata +2 -1
data/README.rdoc
CHANGED
@@ -39,25 +39,6 @@ and *blockers*:
|
|
39
39
|
|
40
40
|
See test/array_logic/rule_test for more examples
|
41
41
|
|
42
|
-
== Combinations that match
|
43
|
-
|
44
|
-
Two methods allow you to determine sample combinations that match the current
|
45
|
-
rule.
|
46
|
-
|
47
|
-
rule = ArrayLogic::Rule.new 'a1 and a2'
|
48
|
-
|
49
|
-
rule.matching_combinations --> [[1,2]]
|
50
|
-
rule.blocking_combinations --> [[1],[2]]
|
51
|
-
|
52
|
-
To limit the number of samples presented, both only use ids used within
|
53
|
-
the rule. For the example above, an array that includes [1,2] would match,
|
54
|
-
and so would [1,2,3]. However, arrays that only contain 1 or 2 would not match
|
55
|
-
(for example [1,3])
|
56
|
-
|
57
|
-
Run example.rb to see some more examples
|
58
|
-
|
59
|
-
ruby /lib/example.rb
|
60
|
-
|
61
42
|
== Functions
|
62
43
|
|
63
44
|
Version 0.2 introduces the concept of functions to ArrayLogic. The function
|
@@ -123,3 +104,35 @@ functions can be combined with other rules:
|
|
123
104
|
|
124
105
|
rule = ArrayLogic::Rule.new '(sum(:id) == 12) and not a6'
|
125
106
|
rule.match(answers) --> false
|
107
|
+
|
108
|
+
== Combinations that match
|
109
|
+
|
110
|
+
Two methods allow you to determine sample combinations that match the current
|
111
|
+
rule.
|
112
|
+
|
113
|
+
rule = ArrayLogic::Rule.new 'a1 and a2'
|
114
|
+
|
115
|
+
rule.matching_combinations --> [[1,2]]
|
116
|
+
rule.blocking_combinations --> [[1],[2]]
|
117
|
+
|
118
|
+
To limit the number of samples presented, both only use ids used within
|
119
|
+
the rule. For the example above, an array that includes [1,2] would match,
|
120
|
+
and so would [1,2,3]. However, arrays that only contain 1 or 2 would not match
|
121
|
+
(for example [1,3])
|
122
|
+
|
123
|
+
=== Combinations and functions
|
124
|
+
|
125
|
+
Combinations are determined by analysing arrays of integers matching the ids
|
126
|
+
found in the rule. This works for most rules but not those that contain functions.
|
127
|
+
|
128
|
+
Therefore, when either matching_combinations, or blocking_combinations are called
|
129
|
+
on a rule that contains a function, an exception is raised.
|
130
|
+
|
131
|
+
rule = ArrayLogic::Rule.new 'sum(:id) > 5'
|
132
|
+
rule.matching_combinations --> raises ArrayLogic::UnableToDetermineCombinationsError
|
133
|
+
|
134
|
+
Thereby handling this issue is passed back to the host application
|
135
|
+
|
136
|
+
Run example.rb to see some more examples
|
137
|
+
|
138
|
+
ruby /lib/example.rb
|
data/lib/array_logic.rb
CHANGED
data/lib/array_logic/rule.rb
CHANGED
@@ -65,6 +65,9 @@ module ArrayLogic
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def combinations_of_identifiers_in_rule_that_pass(&test)
|
68
|
+
if function_pattern =~ rule
|
69
|
+
raise UnableToDetermineCombinationsError, "Unable to determine combinations for rules that include functions"
|
70
|
+
end
|
68
71
|
if rule_valid?
|
69
72
|
combinations = Array.new
|
70
73
|
(1..id_count).each{|n| object_ids_used.combination(n).each{|c| combinations << c if test.call(c)}}
|
data/lib/array_logic/version.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
module ArrayLogic
|
2
|
-
VERSION = "0.2.
|
2
|
+
VERSION = "0.2.4"
|
3
3
|
end
|
4
4
|
|
5
5
|
# History
|
6
6
|
# =======
|
7
7
|
#
|
8
|
+
# Version 0.2.4
|
9
|
+
# -------------
|
10
|
+
# Adds mechanism for handling issue of being unable to determine combinations
|
11
|
+
# for rules with functions, without increasing complexity of combinations methods.
|
12
|
+
# Choice of how to handle the issue can be made in the host app.
|
13
|
+
#
|
8
14
|
# Version 0.2.3
|
9
15
|
# -------------
|
10
16
|
# Bug fix: Identification of ids in rule would see a number preceded by a number
|
@@ -448,6 +448,13 @@ module ArrayLogic
|
|
448
448
|
assert_equal(1, @rule.matching_combinations.length, "should not identify combinations for both occurancies of each id")
|
449
449
|
end
|
450
450
|
|
451
|
+
def test_matching_combinations_with_function
|
452
|
+
@rule.rule = 'sum(:id) == 1'
|
453
|
+
assert_raise UnableToDetermineCombinationsError do
|
454
|
+
@rule.matching_combinations
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
451
458
|
def test_blocking_combinations
|
452
459
|
@rule.rule = 't1 or t2'
|
453
460
|
assert_equal([], @rule.blocking_combinations)
|
@@ -467,6 +474,13 @@ module ArrayLogic
|
|
467
474
|
assert_equal([], @rule.blocking_combinations)
|
468
475
|
end
|
469
476
|
|
477
|
+
def test_blocking_combinations_with_function
|
478
|
+
@rule.rule = 'sum(:id) == 1 and t1'
|
479
|
+
assert_raise UnableToDetermineCombinationsError do
|
480
|
+
@rule.blocking_combinations
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
470
484
|
def test_assigning_rule_on_creation
|
471
485
|
text = 'a1 and a2'
|
472
486
|
rule = Rule.new(text)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: array_logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -20,6 +20,7 @@ extensions: []
|
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
22
|
- lib/array_logic/version.rb
|
23
|
+
- lib/array_logic/exceptions.rb
|
23
24
|
- lib/array_logic/rule.rb
|
24
25
|
- lib/array_logic.rb
|
25
26
|
- lib/example.rb
|