array_logic 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,13 +10,13 @@ The logic for an active record model Answer, looks like this:
10
10
  ....
11
11
  a5 = Answer.find(5)
12
12
 
13
- rule_one.rule = "(a1 and a2) or (a3 and a4)"
13
+ rule_one = ArrayLogic::Rule.new "(a1 and a2) or (a3 and a4)"
14
14
 
15
- rule_two.rule = "a1 and not a2"
15
+ rule_two = ArrayLogic::Rule.new "a1 and not a2"
16
16
 
17
- rule_three.rule = "2 in a1 a2 a3"
17
+ rule_three = ArrayLogic::Rule.new "2 in a1 a2 a3"
18
18
 
19
- rule_four.rule = "(2 in a1 a2 a3) and (1 in a4 a5)"
19
+ rule_four = ArrayLogic::Rule.new "(2 in a1 a2 a3) and (1 in a4 a5)"
20
20
 
21
21
 
22
22
  rule_one rule_two rule_three rule_four
@@ -36,8 +36,7 @@ See test/array_logic/rule_test for more examples
36
36
  Two methods allow you to determine sample combinations that match the current
37
37
  rule.
38
38
 
39
- rule = ArrayLogic::Rule.new
40
- rule.rule = 'a1 and a2'
39
+ rule = ArrayLogic::Rule.new 'a1 and a2'
41
40
  rule.matching_combinations --> [[1,2]]
42
41
  rule.blocking_combinations --> [[1],[2]]
43
42
 
@@ -3,8 +3,8 @@ module ArrayLogic
3
3
  attr_accessor :rule
4
4
  attr_reader :things, :thing_ids
5
5
 
6
- def initialize
7
-
6
+ def initialize(rule = nil)
7
+ @rule = rule
8
8
  end
9
9
 
10
10
  def matches(*array_of_things)
@@ -1,3 +1,3 @@
1
1
  module ArrayLogic
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/example.rb CHANGED
@@ -9,8 +9,7 @@ rule_sets = [
9
9
 
10
10
  rule_sets.each do |rule_set|
11
11
 
12
- rule = ArrayLogic::Rule.new
13
- rule.rule = rule_set
12
+ rule = ArrayLogic::Rule.new(rule_set)
14
13
 
15
14
  puts "----------------------------\n"
16
15
  puts "The rule '#{rule_set}' would match the following:"
@@ -26,8 +25,7 @@ end
26
25
 
27
26
  or_rule = (1..12).to_a.collect{|n| "t#{n}"}.join(" or ")
28
27
 
29
- rule = ArrayLogic::Rule.new
30
- rule.rule = or_rule
28
+ rule = ArrayLogic::Rule.new or_rule
31
29
 
32
30
  require 'benchmark'
33
31
 
@@ -269,6 +269,12 @@ module ArrayLogic
269
269
  @rule.rule = 't1'
270
270
  assert_equal([], @rule.blocking_combinations)
271
271
  end
272
+
273
+ def test_assigning_rule_on_creation
274
+ text = 'a1 and a2'
275
+ rule = Rule.new(text)
276
+ assert_equal(text, rule.rule)
277
+ end
272
278
 
273
279
  end
274
280
  end
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.0.6
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-30 00:00:00.000000000 Z
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Allow a user to define a set of rules, and then test to see if an array
15
15
  of object match those rules.
@@ -19,17 +19,17 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - lib/array_logic/version.rb
22
+ - lib/array_logic.rb
23
23
  - lib/array_logic/thing.rb
24
+ - lib/array_logic/version.rb
24
25
  - lib/array_logic/rule.rb
25
- - lib/array_logic.rb
26
26
  - lib/example.rb
27
27
  - MIT-LICENSE
28
28
  - Rakefile
29
29
  - README.rdoc
30
- - test/array_logic/test_case.rb
31
- - test/array_logic/rule_test.rb
32
30
  - test/array_logic/thing_test.rb
31
+ - test/array_logic/rule_test.rb
32
+ - test/array_logic/test_case.rb
33
33
  homepage: https://github.com/reggieb/array_logic
34
34
  licenses: []
35
35
  post_install_message:
@@ -55,6 +55,6 @@ signing_key:
55
55
  specification_version: 3
56
56
  summary: Matches arrays of objects against logical rules.
57
57
  test_files:
58
- - test/array_logic/test_case.rb
59
- - test/array_logic/rule_test.rb
60
58
  - test/array_logic/thing_test.rb
59
+ - test/array_logic/rule_test.rb
60
+ - test/array_logic/test_case.rb