Giter Site home page Giter Site logo

go-ruler's People

Contributors

hopkinsth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-ruler's Issues

`contains` comparator: maybe not regex

It's used pretty often and probably doesn't need to use a regular expression
ALSO: it would be cool if it supported looking through a slice of things instead of just strings

Or operator inside value

Out of the other rule packages, I found this the best one for my needs. So thank you for developing it.

I have one use-case which I'm sure complicates things further.

I needed the ability to match multiple values within a rule.

For example. I may have the requirement of:

Expected -
People: Elon Musk OR Bill Gates OR Marissa Mayer
AND
Gender: Male

Actual -
People: Elon Musk
Gender: Male

I modified the compare method in ruler.go.

case "eq":
    if strings.Contains(expected.(string), ",") {
        sExpected := strings.Split(expected.(string), ",")

        for _, item := range sExpected {
            if strings.EqualFold(actual.(string), item) {
                return true
            }
        }

        return false
    }

    return actual == expected

Here is an example:

package main

import "github.com/hopkinsth/go-ruler"
import "fmt"

func main() {
    // can also build rules programmatically
    engine := ruler.NewRuler(nil)

    engine.Rule("name").Eq("Elon Musk,Bill Gates,Marissa Mayer")
    engine.Rule("gender").Eq("male")

    context := map[string]interface{}{
        "name":   "Bill Gates",
        "gender": "male",
    }

    result := engine.Test(context)

    fmt.Println(result == true)
}

Or perhaps you want to do something else? But maybe you'll come up with something better and that all other compare methods can use.

Thanks again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.