diff --git a/README.md b/README.md index 7f64c52..1eec33f 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,6 @@ JSON Rules is an abstraction layer over the [Golang Rules Engine](https://github This package allows you to represent rules in JSON format instead of using the original ANTLR query syntax from the nikunjy/rules implementation. -## Example Queries - -You can find example queries in the [examples/](test/examples/) directory. - ## Operations The following operations are supported, matching those available in the [Golang Rules Engine](https://github.com/nikunjy/rules): @@ -33,7 +29,7 @@ The following operations are supported, matching those available in the [Golang | pr | present, will be true if you have a key as true | | not | not of a logical expression | -## JSON Rule Example +## JSON Rule Guide To create a JSON rule, follow these steps: @@ -41,10 +37,7 @@ To create a JSON rule, follow these steps: ```json { - "and": [ - { "==": [{ "var": "y" }, 4] }, - { ">": [{ "var": "x" }, 1] } - ] + "and": [{ "==": [{ "var": "y" }, 4] }, { ">": [{ "var": "x" }, 1] }] } ``` @@ -66,7 +59,12 @@ To create a JSON rule, follow these steps: } ``` +## Examples + +You can find more example json rules in the [examples/](test/examples/) directory. + ## How to use + This example demonstrates how to initialize the parser with a JSON rule and evaluate it against a data set. You can adjust the paths and data as necessary for your specific use case. ```Go diff --git a/parser/parser.go b/parser/parser.go index 6817879..835a235 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -61,8 +61,4 @@ func (p *Parser) formatRule(node map[string]interface{}) string { func (p *Parser) Evaluate(items map[string]interface{}) bool { return parser.Evaluate(p.rule, items) -} - -func (p *Parser) GetRule() string { - return p.rule } \ No newline at end of file diff --git a/test/parser_test.go b/test/parser_test.go index 9ee12c5..d6e5e90 100644 --- a/test/parser_test.go +++ b/test/parser_test.go @@ -1,7 +1,6 @@ package test import ( - "fmt" "path/filepath" "testing" @@ -16,7 +15,6 @@ func TestEqual(t *testing.T) { t.Errorf("%v", err) } - fmt.Println(p.GetRule()) testData := map[string]interface{}{ "x" : 1, } @@ -139,7 +137,7 @@ func TestEqualAndGT(t *testing.T) { } result := p.Evaluate(testData) - assert.False(t, result, p.GetRule()) + assert.False(t, result) }