expression

package
v4.6.3 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 14 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,
		LangEvalString,
		LangEvalSlice,
		LangEvalUrl,
	)

	// 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),
		gval.Function("roundToDecimal", roundToDecimal),
		gval.Function("safeDivide", safeDivide),
	)

	// 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),
		gval.Function("format_date", formatDate),
		gval.Function("get_value_current_day", getValueForCurrentDay),
		gval.Function("get_formatted_duration", getFormattedDuration),
	)

	// 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),
	)

	// LangEvalString is a custom GVal evaluator for handling char arrays (strings)
	LangEvalString = gval.NewLanguage(
		gval.Full(),
		gval.Function("replace", replace),
	)

	LangEvalSlice = gval.NewLanguage(
		gval.Full(),
		gval.Function("contains", contains),
	)

	LangEvalUrl = gval.NewLanguage(
		gval.Full(),
		gval.Function("url_encode", urlEncode),
		gval.Function("url_decode", urlDecode),
	)
)

Functions

func AssertEqual added in v4.2.7

func AssertEqual(t *testing.T, a interface{}, b interface{}, message ...string)

AssertEqual checks if values are equal

func AssertNotEqual added in v4.3.9

func AssertNotEqual(t *testing.T, a interface{}, b interface{}, message ...string)

AssertNotEqual checks if values are not equal

func GetDateKeywords

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

GetDateKeywords return a list of standard date time placeholders

func GetValidDayNames added in v4.3.9

func GetValidDayNames() []string

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