intcondition

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: GPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package intcondition exposes some common integer condition implementations.

Index

Constants

View Source
const (
	// Equal is the sentinel key identifying an int == comparison.
	Equal = "=="
	// GreaterThan is the sentinel key identifying the int > comparison.
	GreaterThan = ">"
	// GreaterThanOrEqual is the sentinel key identifying the int >= comparison.
	GreaterThanOrEqual = ">="
	// ComparisonConditionKey is the sentinel key indicating the condition type is an int comparison.
	ComparisonConditionKey = "intComparison"
	// IsIntConditionKey is the sentinel key identifying that the condition is checking that the argument is an integer.
	IsIntConditionKey = "isInt"
	// LessThan is the sentinel key identifying the int < comparison.
	LessThan = "<"
	// LessThanOrEqual is the sentinel key identifying the int <= comparison.
	LessThanOrEqual = "<="
	// NotEqual is the sentinel key identifying the int != comparison.
	NotEqual = "!="
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ComparisonCondition

type ComparisonCondition struct {
	Type       string `json:"type" yaml:"type"`
	Input      int    `json:"input" yaml:"input"`
	Comparison string `json:"comparison" yaml:"comparison"`
}

ComparisonCondition is an implementation of the condition.Condition interface which converts a match string to an integer, then checks integer equality against Input.

func NewComparisonCondition

func NewComparisonCondition(input int, comparison string) *ComparisonCondition

NewComparisonCondition creates an ComparisonCondition.

func (ComparisonCondition) Evaluate

func (i ComparisonCondition) Evaluate(match string, regex *regexp.Regexp, matchIdx int) (bool, error)

Evaluate evaluates whether a match can be converted to an integer, then performs an integer equality test against Input.

type IsIntCondition

type IsIntCondition struct {
	// Type stores the sentinel which represents the type of Condition implemented.
	Type string `json:"type" yaml:"type"`
}

IsIntCondition is an implementation of the condition.Condition interface which evaluates whether a match string is an integer. Although IsIntCondition is exported for serialization purposes, it is recommended to instantiate new instances of IsIntCondition using NewIsIntCondition.

func NewIsIntCondition

func NewIsIntCondition() *IsIntCondition

NewIsIntCondition creates an IsIntCondition.

func (IsIntCondition) Evaluate

func (i IsIntCondition) Evaluate(match string, regex *regexp.Regexp, matchIdx int) (bool, error)

Evaluate evaluates whether a match string is an integer.

Jump to

Keyboard shortcuts

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