expression

package
v4.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2022 License: MIT Imports: 10 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// LangEval is a custom GVal evaluator for business rules and facts conditions
	// It contains all supported custom functions (math, date, dateopendays, etc.)
	LangEval = gval.NewLanguage(
		gval.Full(),
		LangExprMath,
		LangEvalDate,
		LangEvalDateOpenDays,
		LangAdvancedInfix,
		LangEvalMap,
	)

	// LangExprMath is a custom GVal evaluator for business rules and facts conditions
	// It contains custom functions related to math
	LangExprMath = gval.NewLanguage(
		gval.Full(),
		gval.Function("length", length),
		gval.Function("max", max),
		gval.Function("min", min),
		gval.Function("sum", sum),
		gval.Function("average", average),
	)

	// LangEvalDate is a custom GVal evaluator for business rules and facts conditions
	// It contains custom functions related to date
	LangEvalDate = gval.NewLanguage(
		gval.Full(),
		gval.Function("dayOfWeek", dayOfWeek),
		gval.Function("day", day),
		gval.Function("month", month),
		gval.Function("year", year),
		gval.Function("startOf", startOf),
		gval.Function("endOf", endOf),
		gval.Function("datemillis", dateToMillis),
		gval.Function("calendar_add", addDurationDays),
		gval.Function("calendar_delay", delayInDays),
		gval.Function("truncate_date", truncateDate),
		gval.Function("extract_from_date", extractFromDate),
	)

	// LangEvalDateOpenDays is a custom GVal evaluator for business rules and facts conditions
	// It contains custom functions related to date (opendays support)
	LangEvalDateOpenDays = gval.NewLanguage(
		gval.Full(),
		gval.Function("calendar_add_od", addDurationOpenDays),
		gval.Function("calendar_delay_od", delayInOpenDays),
	)

	// LangAdvancedInfix is a custom Gval evaluator for maps operations
	LangAdvancedInfix = gval.NewLanguage(
		gval.Full(),
		gval.InfixOperator("+", advancedAddition),
		gval.InfixOperator("-", advancedSubtraction),
		gval.InfixOperator("*", advancedMultiplication),
		gval.InfixOperator("/", advancedDivision),
	)

	LangEvalMap = gval.NewLanguage(
		gval.Full(),
		gval.Function("flatten_fact", flattenFact),
	)
)

Functions

func GetDateKeywords

func GetDateKeywords(t time.Time) map[string]interface{}

GetDateKeywords return a list of standard date time placeholders

func IsInvalidNumber

func IsInvalidNumber(input interface{}) bool

IsInvalidNumber return true if the input interface is a not valid number

func Process

func Process(langEval gval.Language, expression string, variables map[string]interface{}) (interface{}, error)

Process process an expression with a map of properties using a specific GVal language

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL