Skip to content

Commit

Permalink
V1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
intersel committed Mar 11, 2017
1 parent dc7145c commit f091d37
Show file tree
Hide file tree
Showing 5 changed files with 487 additions and 208 deletions.
115 changes: 72 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,56 @@
Javascript configurator to match rules on massive number of objects

#What is JamRules
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!
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!

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.
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.

#Example
Example:
* I sell red and white trousers and yellow and blue shirts through different kind of packs of products:
##my set of objects

I sell red and white trousers and yellow and blue shirts through different kind of packs of 2 products:
* packs of 2 trousers
* packs with a trouser and shirt
* packs with two shirts
* etc...
* I'll give a promo coupon for packs that

For the example, we decide that an object is a "pack" with the following properties:
* property "object1" that can have the values "trouser" or "shirt"
* property "object1color" that can have the values "blue" or "yellow" or "white"
* property "object2" that can have the values "trouser" or "shirt"
* property "object2color" that can have the values "blue" or "yellow" or "white"

##my selection rules of objects

I want to give a promo coupon for packs that
* have two trousers
* or have a trouser with a shirt
* nothing if the trousers in the pack are of different colors
* nothing for the other kind of packs

We will translate these rules to have a coupon as following:
* object1 and object2 have to be a trouser
* AND
* object1color has to be different from object2color
OR
* object1 has to be a trouser
* AND
* object2 has to be a shirt
OR
* object1 has to be a shirt
* AND
* object2 has to be a trouser

Which packs should have a promo code?

Jamrules will be able to tell you!
You configure Jamrules configurator according to one of the pack configurations and run the test.
* add the objects to test in jamrules
* configure Jamrules configurator to select some packs, like select the packs that has a white trouser and a blue shirt.
* run the test:
* jamrules will tell to the packs that have a white trouser and a blue shirts if they have a coupon.
* It will tell to the others packs that they don't match the selection or the rules.

JamRules will select the packs that match the configuration if it respects the rules in order to give them the promo code.

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...
Expand All @@ -47,9 +76,9 @@ no demo available :-( will come quickly!
rulesEngine.addRule("SameColorTrousoursPack","FirstTrouser",'MatchPropertyValue("object1","trouser")');
rulesEngine.addRule("SameColorTrousoursPack","FirstTrouser",'MatchPropertyValue("object2","trouser")');
// and have same color
rulesEngine.addRule("SameColorTrousoursPack","SameColor1",'MatchPropertiesValue("object1Color","object1Color")');
rulesEngine.addRule("SameColorTrousoursPack","SameColor2",'MatchPropertiesValue("object1Color","object2Color")');
rulesEngine.addRule("SameColorTrousoursPack","SameColor3",'MatchPropertiesValue("object2Color","object1Color")');
rulesEngine.addRule("SameColorTrousoursPack","SameColor1",'MatchPropertiesSameValue("object1Color","object1Color")');
rulesEngine.addRule("SameColorTrousoursPack","SameColor2",'MatchPropertiesSameValue("object1Color","object2Color")');
rulesEngine.addRule("SameColorTrousoursPack","SameColor3",'MatchPropertiesSameValue("object2Color","object1Color")');

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

## Add your elements to test - addElement
## Add your objects to test - addObject

```javascript

Expand Down Expand Up @@ -103,47 +132,47 @@ no demo available :-( will come quickly!
, matched:matched
, notmatched:notmatched
};
rulesEngine.addElement(pack1);
rulesEngine.addElement(pack2);
rulesEngine.addElement(pack3);
rulesEngine.addObject(pack1);
rulesEngine.addObject(pack2);
rulesEngine.addObject(pack3);
```
## Create the configuration to test
```javascript
//prepare configuration for test "2 white trousers"
rulesEngine.setProperty("object1","trouser",1,false);
rulesEngine.setProperty("object2","trouser",1,false);
rulesEngine.setProperty("object1Color","white",1,false);
rulesEngine.selectConfigurationPropertyValue("object1","trouser",1,false);
rulesEngine.selectConfigurationPropertyValue("object2","trouser",1,false);
rulesEngine.selectConfigurationPropertyValue("object1Color","white",1,false);
// will select pack1 and call its 'matched' function,
//will not match with pack2 and pack3 and call their 'unmatched' function
rulesEngine.setProperty("object2Color","white",1);
rulesEngine.selectConfigurationPropertyValue("object2Color","white",1);

//prepare configuration "a white trousers and blue shirt"
rulesEngine.setProperty("object1","trouser",1,false);
rulesEngine.setProperty("object2","shirt",1,false);
rulesEngine.setProperty("object1Color","white",1,false);
rulesEngine.setProperty("object2Color","blue",1,false);
rulesEngine.selectConfigurationPropertyValue("object1","trouser",1,false);
rulesEngine.selectConfigurationPropertyValue("object2","shirt",1,false);
rulesEngine.selectConfigurationPropertyValue("object1Color","white",1,false);
rulesEngine.selectConfigurationPropertyValue("object2Color","blue",1,false);
// will select pack2 and call its 'matched' function,
//will not match with pack1 and pack3 and call their 'unmatched' function
rulesEngine.setProperty("object2Color","white",1);
rulesEngine.selectConfigurationPropertyValue("object2Color","white",1);
```

#Available API

##Matching functions

###function MatchProperty(aPropertyName)
tests if at least a property value of a property is shared between the configuration and the element
tests if at least a property value of a property is shared between the configuration and the object

####parameters
* aPropertyName: a property name

####returns
returns true if any property value for a given aPropertyName is set in the profile element and in the configuration property set
returns true if any property value for a given aPropertyName is set in the profile object and in the configuration property set

####Example

* element.priority.priority1=1
* element.technician.technician1=1
* object.priority.priority1=1
* object.technician.technician1=1
* configuration.priority.priority1=1
* configuration.priority.priority2=0
* configuration.technician.technician1=0
Expand All @@ -152,57 +181,57 @@ returns true if any property value for a given aPropertyName is set in the profi
* MatchProperty('technician') -> no match

###function MatchPropertyValue(aPropertyName,aPropertyValue)
tests if a given property value is set for configuration and the element
tests if a given property value is set for configuration and the object

####parameters
* aPropertyName: a property name
* aPropertyValue: a value of aPropertyName

####returns
returns true if the configuration for the aPropertyName.aPropertyValue == the one defined for the current elementProfile being tested
returns true if the configuration for the aPropertyName.aPropertyValue == the one defined for the current object profile being tested

####Example
* element.priority.priority1=1
* element.technician.technician1=1
* object.priority.priority1=1
* object.technician.technician1=1
* configuration.priority.priority1=1
* configuration.technician.technician1=0
* MatchPropertyValue('priority','priority1') -> match
* MatchPropertyValue('technician','technician1') -> no match

###function MatchPropertiesValue(aConfigurationPropertyName,aElementPropertyName,aPropertyValue)
tests if a property value exists and is the same between a configurator property and the element property
###function MatchPropertiesSameValue(aConfigurationPropertyName,anObjectPropertyName,aPropertyValue)
tests if a property value exists and is the same between a configurator property and the object property

####parameters

* aConfigurationPropertyName: a configuration property name
* aElementPropertyName: a element property Name
* anObjectPropertyName: a object property Name
* aPropertyValue: a value of aPropertyName

####returns

returns true if aPropertyValue in aConfigurationPropertyName and in aElementPropertyName are both set
returns true if aPropertyValue in aConfigurationPropertyName and in anObjectPropertyName are both set

####Example

* element.priority.priority1=1
* object.priority.priority1=1
* configuration.priority.priority1=0
* configuration.activity.priority1=1
* configuration.strawberry.priority2=1
* MatchPropertiesValue('activity','priority','priority1') -> match
* MatchPropertiesValue('strawberry','priority','priority1') -> no match
* MatchPropertiesSameValue('activity','priority','priority1') -> match
* MatchPropertiesSameValue('strawberry','priority','priority1') -> no match

###function MatchProperties(aConfigurationPropertyName,aElementPropertyName)
tests if at least a property value exists and is set between the configurator property and the element property
###function MatchProperties(aConfigurationPropertyName,anObjectPropertyName)
tests if at least a property value exists and is set between the configurator property and the object property

####parameters
* aConfigurationPropertyName: a configuration property name
* aElementPropertyName: a element property Name
* anObjectPropertyName: a object property Name

####returns
returns true if it exists a value of aConfigurationPropertyName that is the same that in aElementPropertyName
returns true if it exists a value of aConfigurationPropertyName that is the same that in anObjectPropertyName

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

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

#Official website
Expand Down
Loading

0 comments on commit f091d37

Please sign in to comment.