rulz 1.0.3 → 1.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.
- checksums.yaml +4 -4
- data/lib/rulz.rb +1 -0
- data/lib/rulz/conditions/boolean.rb +6 -6
- data/lib/rulz/conditions/conditions.rb +3 -0
- data/lib/rulz/conditions/number.rb +41 -0
- data/lib/rulz/version.rb +1 -1
- data/spec/condition_spec.rb +24 -5
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3345b4bf61316d345428cb0e24052ff4e8fa09c2
|
4
|
+
data.tar.gz: d035a958e7595714bb8380416301d8b21ef2dd1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60591bf21dd52b4e00a028b98ef89885b85cf34298c09233d13c06b262f089d5931294a4fb3ce514945a1063e2e08e2b50bd438fc54dbfaf2ec60bea764bdbc9
|
7
|
+
data.tar.gz: a73df0759fd139c7f8c07f19db31876757fa1b21e6e5d546e806b7ae8ed2f2b1478462cac0b1f16a11ba67b42e04f039d0896fa5b07b341e130d160e07877610
|
data/lib/rulz.rb
CHANGED
@@ -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
|
data/lib/rulz/version.rb
CHANGED
data/spec/condition_spec.rb
CHANGED
@@ -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.
|
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
|