Skip to content

Commit f091d37

Browse files
committed
V1.1.0
1 parent dc7145c commit f091d37

5 files changed

Lines changed: 487 additions & 208 deletions

File tree

README.md

Lines changed: 72 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,56 @@
22
Javascript configurator to match rules on massive number of objects
33

44
#What is JamRules
5-
Let's say you have a set of objects with parameters and you'd like to filter them according to a configuration of these parameters and specific rules of choices... then JamRules is for you!
5+
Let's say you have a set of objects with properties and you'd like to filter them according to a user configuration of these properties and specific rules of choices... then JamRules is for you!
66

7-
JamRules allows you to configure a set of parameters and a set of rules of matching, then test if objects match against the rules and the configuration.
7+
JamRules allows you to configure a set of parameters and a set of rules of matching, then it will test and select your objects accordingly to your configuration and the defined rules.
88

99
#Example
1010
Example:
11-
* I sell red and white trousers and yellow and blue shirts through different kind of packs of products:
11+
##my set of objects
12+
13+
I sell red and white trousers and yellow and blue shirts through different kind of packs of 2 products:
1214
* packs of 2 trousers
1315
* packs with a trouser and shirt
1416
* packs with two shirts
1517
* etc...
16-
* I'll give a promo coupon for packs that
18+
19+
For the example, we decide that an object is a "pack" with the following properties:
20+
* property "object1" that can have the values "trouser" or "shirt"
21+
* property "object1color" that can have the values "blue" or "yellow" or "white"
22+
* property "object2" that can have the values "trouser" or "shirt"
23+
* property "object2color" that can have the values "blue" or "yellow" or "white"
24+
25+
##my selection rules of objects
26+
27+
I want to give a promo coupon for packs that
1728
* have two trousers
1829
* or have a trouser with a shirt
1930
* nothing if the trousers in the pack are of different colors
2031
* nothing for the other kind of packs
2132

33+
We will translate these rules to have a coupon as following:
34+
* object1 and object2 have to be a trouser
35+
* AND
36+
* object1color has to be different from object2color
37+
OR
38+
* object1 has to be a trouser
39+
* AND
40+
* object2 has to be a shirt
41+
OR
42+
* object1 has to be a shirt
43+
* AND
44+
* object2 has to be a trouser
45+
2246
Which packs should have a promo code?
2347

2448
Jamrules will be able to tell you!
25-
You configure Jamrules configurator according to one of the pack configurations and run the test.
49+
* add the objects to test in jamrules
50+
* configure Jamrules configurator to select some packs, like select the packs that has a white trouser and a blue shirt.
51+
* run the test:
52+
* jamrules will tell to the packs that have a white trouser and a blue shirts if they have a coupon.
53+
* It will tell to the others packs that they don't match the selection or the rules.
54+
2655
JamRules will select the packs that match the configuration if it respects the rules in order to give them the promo code.
2756

2857
Of course, that's a simple example but you can imagine how rules and kind of packs can become numerous and answers may become quickly hard to give...
@@ -47,9 +76,9 @@ no demo available :-( will come quickly!
4776
rulesEngine.addRule("SameColorTrousoursPack","FirstTrouser",'MatchPropertyValue("object1","trouser")');
4877
rulesEngine.addRule("SameColorTrousoursPack","FirstTrouser",'MatchPropertyValue("object2","trouser")');
4978
// and have same color
50-
rulesEngine.addRule("SameColorTrousoursPack","SameColor1",'MatchPropertiesValue("object1Color","object1Color")');
51-
rulesEngine.addRule("SameColorTrousoursPack","SameColor2",'MatchPropertiesValue("object1Color","object2Color")');
52-
rulesEngine.addRule("SameColorTrousoursPack","SameColor3",'MatchPropertiesValue("object2Color","object1Color")');
79+
rulesEngine.addRule("SameColorTrousoursPack","SameColor1",'MatchPropertiesSameValue("object1Color","object1Color")');
80+
rulesEngine.addRule("SameColorTrousoursPack","SameColor2",'MatchPropertiesSameValue("object1Color","object2Color")');
81+
rulesEngine.addRule("SameColorTrousoursPack","SameColor3",'MatchPropertiesSameValue("object2Color","object1Color")');
5382

5483
//promo if a trouser and a shirt
5584
rulesEngine.createRulesSet("TrouserShirtPack",["object1","object2"]);
@@ -67,7 +96,7 @@ no demo available :-( will come quickly!
6796
rulesEngine.compileRules();
6897
```
6998

70-
## Add your elements to test - addElement
99+
## Add your objects to test - addObject
71100

72101
```javascript
73102

@@ -103,47 +132,47 @@ no demo available :-( will come quickly!
103132
, matched:matched
104133
, notmatched:notmatched
105134
};
106-
rulesEngine.addElement(pack1);
107-
rulesEngine.addElement(pack2);
108-
rulesEngine.addElement(pack3);
135+
rulesEngine.addObject(pack1);
136+
rulesEngine.addObject(pack2);
137+
rulesEngine.addObject(pack3);
109138
```
110139
## Create the configuration to test
111140
```javascript
112141
//prepare configuration for test "2 white trousers"
113-
rulesEngine.setProperty("object1","trouser",1,false);
114-
rulesEngine.setProperty("object2","trouser",1,false);
115-
rulesEngine.setProperty("object1Color","white",1,false);
142+
rulesEngine.selectConfigurationPropertyValue("object1","trouser",1,false);
143+
rulesEngine.selectConfigurationPropertyValue("object2","trouser",1,false);
144+
rulesEngine.selectConfigurationPropertyValue("object1Color","white",1,false);
116145
// will select pack1 and call its 'matched' function,
117146
//will not match with pack2 and pack3 and call their 'unmatched' function
118-
rulesEngine.setProperty("object2Color","white",1);
147+
rulesEngine.selectConfigurationPropertyValue("object2Color","white",1);
119148

120149
//prepare configuration "a white trousers and blue shirt"
121-
rulesEngine.setProperty("object1","trouser",1,false);
122-
rulesEngine.setProperty("object2","shirt",1,false);
123-
rulesEngine.setProperty("object1Color","white",1,false);
124-
rulesEngine.setProperty("object2Color","blue",1,false);
150+
rulesEngine.selectConfigurationPropertyValue("object1","trouser",1,false);
151+
rulesEngine.selectConfigurationPropertyValue("object2","shirt",1,false);
152+
rulesEngine.selectConfigurationPropertyValue("object1Color","white",1,false);
153+
rulesEngine.selectConfigurationPropertyValue("object2Color","blue",1,false);
125154
// will select pack2 and call its 'matched' function,
126155
//will not match with pack1 and pack3 and call their 'unmatched' function
127-
rulesEngine.setProperty("object2Color","white",1);
156+
rulesEngine.selectConfigurationPropertyValue("object2Color","white",1);
128157
```
129158

130159
#Available API
131160

132161
##Matching functions
133162

134163
###function MatchProperty(aPropertyName)
135-
tests if at least a property value of a property is shared between the configuration and the element
164+
tests if at least a property value of a property is shared between the configuration and the object
136165

137166
####parameters
138167
* aPropertyName: a property name
139168

140169
####returns
141-
returns true if any property value for a given aPropertyName is set in the profile element and in the configuration property set
170+
returns true if any property value for a given aPropertyName is set in the profile object and in the configuration property set
142171

143172
####Example
144173

145-
* element.priority.priority1=1
146-
* element.technician.technician1=1
174+
* object.priority.priority1=1
175+
* object.technician.technician1=1
147176
* configuration.priority.priority1=1
148177
* configuration.priority.priority2=0
149178
* configuration.technician.technician1=0
@@ -152,57 +181,57 @@ returns true if any property value for a given aPropertyName is set in the profi
152181
* MatchProperty('technician') -> no match
153182

154183
###function MatchPropertyValue(aPropertyName,aPropertyValue)
155-
tests if a given property value is set for configuration and the element
184+
tests if a given property value is set for configuration and the object
156185

157186
####parameters
158187
* aPropertyName: a property name
159188
* aPropertyValue: a value of aPropertyName
160189

161190
####returns
162-
returns true if the configuration for the aPropertyName.aPropertyValue == the one defined for the current elementProfile being tested
191+
returns true if the configuration for the aPropertyName.aPropertyValue == the one defined for the current object profile being tested
163192

164193
####Example
165-
* element.priority.priority1=1
166-
* element.technician.technician1=1
194+
* object.priority.priority1=1
195+
* object.technician.technician1=1
167196
* configuration.priority.priority1=1
168197
* configuration.technician.technician1=0
169198
* MatchPropertyValue('priority','priority1') -> match
170199
* MatchPropertyValue('technician','technician1') -> no match
171200

172-
###function MatchPropertiesValue(aConfigurationPropertyName,aElementPropertyName,aPropertyValue)
173-
tests if a property value exists and is the same between a configurator property and the element property
201+
###function MatchPropertiesSameValue(aConfigurationPropertyName,anObjectPropertyName,aPropertyValue)
202+
tests if a property value exists and is the same between a configurator property and the object property
174203

175204
####parameters
176205

177206
* aConfigurationPropertyName: a configuration property name
178-
* aElementPropertyName: a element property Name
207+
* anObjectPropertyName: a object property Name
179208
* aPropertyValue: a value of aPropertyName
180209

181210
####returns
182211

183-
returns true if aPropertyValue in aConfigurationPropertyName and in aElementPropertyName are both set
212+
returns true if aPropertyValue in aConfigurationPropertyName and in anObjectPropertyName are both set
184213

185214
####Example
186215

187-
* element.priority.priority1=1
216+
* object.priority.priority1=1
188217
* configuration.priority.priority1=0
189218
* configuration.activity.priority1=1
190219
* configuration.strawberry.priority2=1
191-
* MatchPropertiesValue('activity','priority','priority1') -> match
192-
* MatchPropertiesValue('strawberry','priority','priority1') -> no match
220+
* MatchPropertiesSameValue('activity','priority','priority1') -> match
221+
* MatchPropertiesSameValue('strawberry','priority','priority1') -> no match
193222

194-
###function MatchProperties(aConfigurationPropertyName,aElementPropertyName)
195-
tests if at least a property value exists and is set between the configurator property and the element property
223+
###function MatchProperties(aConfigurationPropertyName,anObjectPropertyName)
224+
tests if at least a property value exists and is set between the configurator property and the object property
196225

197226
####parameters
198227
* aConfigurationPropertyName: a configuration property name
199-
* aElementPropertyName: a element property Name
228+
* anObjectPropertyName: a object property Name
200229

201230
####returns
202-
returns true if it exists a value of aConfigurationPropertyName that is the same that in aElementPropertyName
231+
returns true if it exists a value of aConfigurationPropertyName that is the same that in anObjectPropertyName
203232

204233
####Example
205-
* element.priority.priority1=1
234+
* object.priority.priority1=1
206235
* configuration.priority.priority1=0
207236
* configuration.activity.priority1=1
208237
* configuration.strawberry.priority2=1
@@ -221,7 +250,7 @@ matching rule function, tests if the property in the configurator has its value
221250
returns true if the configuration for the aPropertyName.aPropertyValue == valueSet
222251

223252
####Example
224-
* element.priority.priority1=1
253+
* object.priority.priority1=1
225254
* configuration.priority.priority1=0
226255
* configuration.activity.priority1=1
227256
* configuration.strawberry.priority2=1
@@ -238,7 +267,7 @@ To work properly, you need to include the following javascript library:
238267
* this library brings some very usefull feature on the usual javascript setTimeout function like Debouncing, Delays & Polling Loops, Hover Intent...
239268
* `<script type="text/javascript" src="extlib/jquery.dotimeout.js"></script>`
240269
* attrchange by Selvakumar Arumugam](http://meetselva.github.io/attrchange/)
241-
* a simple jQuery function to bind a listener function to any HTML element on attribute change
270+
* a simple jQuery function to bind a listener function to any HTML object on attribute change
242271
* `<script type="text/javascript" src="extlib/jquery.attrchange.js"></script>`
243272

244273
#Official website

0 commit comments

Comments
 (0)