Skip to content

Commit 72103e6

Browse files
committed
patch
1 parent 4e27c8e commit 72103e6

7 files changed

Lines changed: 304 additions & 138 deletions

File tree

README.md

Lines changed: 78 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,17 @@ For the example, we will translate this description defining the "pack" as our j
3232
* property "object2" that can have the values "trouser" or "shirt"
3333
* property "object2color" that can have the values "blue" or "yellow" or "white"
3434

35-
Here is an exemple of how a pack should be defined for jamrules:
35+
Here is an exemple of how a pack may defined for jamrules:
3636
```javascript
3737

3838
var pack1={
39-
propertiesSet:{
40-
object1:{trouser:1}
41-
, object2:{shirt:1}
42-
, object1Color:{blue:1}
43-
, object2Color:{white:1}
44-
}
39+
object1:"trouser"
40+
, object2:"shirt"
41+
, object1Color:"blue"
42+
, object2Color:"white"
4543
};
4644

47-
rulesEngine.addObject(pack1);
45+
rulesEngine.addPropertyObject(pack1);
4846

4947
```
5048

@@ -98,10 +96,12 @@ JamRules will select the packs that match the configuration if it respects the r
9896
To do that, just define a "matched" function on your object like in this example:
9997

10098
```javascript
101-
102-
var pack1.matched=function(aRuleEngine){
99+
100+
var pack1 ={property1:20}
101+
pack1.matched=function(aRuleEngine){
103102
alert("it matches");
104103
}
104+
rulesEngine.addPropertyObject(pack1);
105105
```
106106

107107
You can define a "notmatched" that will be called if the tested object did not match the rules...
@@ -136,19 +136,45 @@ no demo available :-( will come quickly!
136136
```javascript
137137

138138
//initialisation of jamrules and its configurator
139-
var rulesEngine = new jamrules($('#filterbox'),{debug:true});
139+
var rulesEngine = jamrules.build({
140+
debug: <boolean>,
141+
matched: <a function to call when the rule find a match>,
142+
notmatched: <a function to call when the rule did not find a match>
143+
jqueryObj: <aJqueryObject>,
144+
});
140145
```
141146

142-
# The JamRules Objects
143-
In order to test objects with jamrules, you need to format your data in this format:
147+
## the options parameter
148+
### debug
149+
if true, the rule engine will send debug message on the console
150+
151+
152+
### the Matched and NotMatched functions
153+
154+
The "matched" and "notmatched" functions are called whenever the rule engine matches an object profile.
155+
156+
They have the following parameters:
157+
* aListOfMatchedObjects: the list of objects that matched the rule
158+
159+
### jqueryObj -internal parameter-
160+
jquery Object to bind with the iFSM engine.
161+
162+
# The JamRules Objects
163+
In order to test objects with jamrules, you have to give it objects to test against the rules defined in the rule engine.
164+
165+
These objects may be any with properties...
166+
167+
Internally, the objects are formatted in order to process the matching functions and rules, the internal format of your data in jamrules will be :
144168

145169
```javascript
146170
{
147171
propertiesSet:{
148172
<propertyName1>:{<propertyValue1:<0|1>,<propertyValue2:<0|1>, ...},
149173
<propertyName2>:{<propertyValue1:<0|1>,<propertyValue2:<0|1>, ...},
150174
...
151-
}
175+
},
176+
matched: <a function when it matches>,
177+
notmatched: <a function when it does not match>,
152178
}
153179
```
154180

@@ -225,14 +251,35 @@ rulesEngine.addRule("SameColorTrousersPack","O2Trouser",'ObjectPropertiesSameVal
225251
```
226252
# The JamRules API
227253

254+
## addPropertyObject(anObject<, aMatchingFunction, aNotMatchingFunction>)
255+
256+
Add an object to the list of objects to test against rules.
257+
258+
* object with its properties plus these optional ones
259+
* matched (otion):<function name to call when a rule will match for the object>
260+
* notmatched (option):<function name to call when there is a change but object does not match any rules>
261+
* aMatchingFunction (option): the matching function, same as to define the "matched" property in the object
262+
* aNotMatchingFunction (option): the matching function, same as to define the "notmatched" property in the object
263+
264+
### Example
265+
```javascript
266+
ruleEngine = jamrules.build();
267+
var anObject = {
268+
object1Color : "white"
269+
};
270+
myMatchFunction = function(){alert("Hello:"+this.object1Color)};
271+
rulesEngine.addObject(onObject,myMatchFunction);
272+
```
273+
228274
## addObject(anObject)
229275
Add an object to the list of objects to test against rules.
230276
231277
### parameters
232-
* anObject: a object to test in jamrule
278+
* anObject: a object to test in jamrules in jamrules format
233279
234280
### Example
235281
```javascript
282+
ruleEngine = jamrules.build();
236283
var anObject = {
237284
propertiesSet : {
238285
object1Color : {
@@ -245,7 +292,10 @@ var anObject = {
245292
rulesEngine.addObject(onObject);
246293
```
247294
248-
## _addObject(anObject)
295+
## _addObject(anObject) - static function
296+
297+
Remark: to be called with jamrules variables.
298+
249299
Add an object to the list of objects to test against rules.
250300
This function differs from addObject in the way that all the jamrules will share the objects added this way.
251301
So, you include once your objects in the first jamrules object and then they will be processed by all the other rules.
@@ -264,7 +314,7 @@ var anObject = {
264314
matched : myMatchFunction,
265315
notmatched : null
266316
};
267-
rulesEngine._addObject(onObject);
317+
jamrules._addObject(onObject);
268318
```
269319
270320
## createRulesSet(aRulesGroup, ruleEvents)
@@ -563,6 +613,17 @@ To work properly, you need to include the following javascript library:
563613
# Official website
564614
565615
# FAQ
616+
## How to get why the rule did not match
617+
618+
You can get the reasons why the engine did not match by accessing to the following reason property :
619+
620+
```javascript
621+
var notmatched=function(aJamRules){
622+
var reason = aJamRules.myRulesEngine.opts.reason; //array of strings with the rules that did not match
623+
}
624+
```
625+
626+
566627
567628
# Contact
568629
If you have any ideas, feedback, requests or bug reports, you can reach me at github@intersel.org,

0 commit comments

Comments
 (0)