rulz 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de63333148931a63988610e1ac333419a3e6f1fe
4
- data.tar.gz: a26e35c475f09dc16c2159d0e95249d53d274e6d
3
+ metadata.gz: 3345b4bf61316d345428cb0e24052ff4e8fa09c2
4
+ data.tar.gz: d035a958e7595714bb8380416301d8b21ef2dd1c
5
5
  SHA512:
6
- metadata.gz: acf732fcdb41c69d99b1d94f14fd13e3db579b665053f678c4453bcb50381658ec4b5781026d3eb936bc5ff48566c80f7185aebfd210d9e1762cf26c769210a5
7
- data.tar.gz: 2a0b0b54739038dafa7332d0337a17578e957b10205f34b234b760200a6e205dec17364f24a50d8f58516ce6e791f6a3e32bd42d9f1af069f29574c1aabfe867
6
+ metadata.gz: 60591bf21dd52b4e00a028b98ef89885b85cf34298c09233d13c06b262f089d5931294a4fb3ce514945a1063e2e08e2b50bd438fc54dbfaf2ec60bea764bdbc9
7
+ data.tar.gz: a73df0759fd139c7f8c07f19db31876757fa1b21e6e5d546e806b7ae8ed2f2b1478462cac0b1f16a11ba67b42e04f039d0896fa5b07b341e130d160e07877610
@@ -5,6 +5,7 @@ require "rulz/evaluator"
5
5
  require "rulz/action"
6
6
  require "rulz/rule"
7
7
  require "rulz/conditions/boolean"
8
+ require "rulz/conditions/number"
8
9
  require "rulz/conditions/comparison"
9
10
  require "rulz/conditions/container"
10
11
  require "rulz/conditions/string"
@@ -5,11 +5,11 @@ module Rulz
5
5
  reciever.class_eval do
6
6
  define_rulz do
7
7
  attribute attr do
8
- condition "true" do
8
+ condition "is true" do
9
9
  send(attr)
10
10
  end
11
- condition "false" do
12
- opposite_of "true"
11
+ condition "is false" do
12
+ opposite_of "is true"
13
13
  end
14
14
  end
15
15
  end
@@ -19,11 +19,11 @@ module Rulz
19
19
  def self.included(base)
20
20
  base.class_eval do
21
21
  define_rulz do
22
- condition "true" do
22
+ condition "is true" do
23
23
  it
24
24
  end
25
- condition "false" do
26
- opposite_of "true"
25
+ condition "is false" do
26
+ opposite_of "is true"
27
27
  end
28
28
  end
29
29
  end
@@ -4,10 +4,13 @@ module Rulz
4
4
  case kind
5
5
  when :integer
6
6
  Comparison.load_conditions(reciever, attribute)
7
+ Number.load_conditions(reciever, attribute)
7
8
  when :float
8
9
  Comparison.load_conditions(reciever, attribute)
10
+ Number.load_conditions(reciever, attribute)
9
11
  when :decimal
10
12
  Comparison.load_conditions(reciever, attribute)
13
+ Number.load_conditions(reciever, attribute)
11
14
  when :string
12
15
  Container.load_conditions(reciever, attribute)
13
16
  String.load_conditions(reciever, attribute)
@@ -0,0 +1,41 @@
1
+ module Rulz
2
+ module Conditions
3
+ module Number
4
+ def self.load_conditions(reciever, attr)
5
+ reciever.class_eval do
6
+ define_rulz do
7
+ attribute attr do
8
+ condition "is positive" do
9
+ send(attr) > 0
10
+ end
11
+ condition "is negative" do |other|
12
+ send(attr) < 0
13
+ end
14
+ condition "is zero" do |other|
15
+ send(attr) == 0
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+
23
+ def self.included(base)
24
+ base.class_eval do
25
+ define_rulz do
26
+ condition "is positive" do
27
+ it > 0
28
+ end
29
+ condition "is negative" do |other|
30
+ it < 0
31
+ end
32
+ condition "is zero" do |other|
33
+ it == 0
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Rulz
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -66,7 +66,10 @@ describe "condition" do
66
66
  include Rulz
67
67
  include Rulz::Conditions::Boolean
68
68
  end
69
-
69
+ class Fixnum
70
+ include Rulz
71
+ include Rulz::Conditions::Number
72
+ end
70
73
  end
71
74
 
72
75
  it "should recognize contains" do
@@ -115,15 +118,31 @@ describe "condition" do
115
118
  end
116
119
 
117
120
  it "should recognize true" do
118
- true.condition_true?("true").should be_true
119
- false.condition_true?("true").should be_false
121
+ true.condition_true?("is true").should be_true
122
+ false.condition_true?("is true").should be_false
120
123
  end
121
124
 
122
125
  it "should recognize false" do
123
- false.condition_true?("false").should be_true
124
- true.condition_true?("false").should be_false
126
+ false.condition_true?("is false").should be_true
127
+ true.condition_true?("is false").should be_false
128
+ end
129
+
130
+ it "should recognize is zero" do
131
+ 0.condition_true?("is zero").should be_true
132
+ 1.condition_true?("is zero").should be_false
125
133
  end
126
134
 
135
+ it "should recognize is positive" do
136
+ 1.condition_true?("is positive").should be_true
137
+ 0.condition_true?("is positive").should be_false
138
+ end
139
+
140
+ it "should recognize is negative" do
141
+ (-1).condition_true?("is negative").should be_true
142
+ 1.condition_true?("is negative").should be_false
143
+ end
144
+
145
+
127
146
  end
128
147
 
129
148
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rulz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chase Conklin
@@ -89,6 +89,7 @@ files:
89
89
  - lib/rulz/conditions/comparison.rb
90
90
  - lib/rulz/conditions/conditions.rb
91
91
  - lib/rulz/conditions/container.rb
92
+ - lib/rulz/conditions/number.rb
92
93
  - lib/rulz/conditions/string.rb
93
94
  - lib/rulz/definer.rb
94
95
  - lib/rulz/evaluator.rb