Allow minimum_matches = -1

This commit is contained in:
JeremyStar™ 2024-05-11 02:48:12 +02:00
parent 48380cd8c3
commit 1616c7b37d
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 5 additions and 2 deletions

View file

@ -50,7 +50,7 @@ Applies to **float**.
Checks whenether at least one value matches `data`.
Applies to all data types.
### *CoreValidationSingle* <u>contains</u>(*Array[String]* <u>values</u>, *int* <u>minimum_matches</u> = *1*)
Ensures that [param data] contains at least <`minimum_matches`> values. \
Ensures that [param data] contains at least <`minimum_matches`> (or all if set to `-1`) values. \
Applies to **String** & **StringName**.
### *CoreValidationSingle* <u>matches_regex</u>(*String* <u>regex_string</u>)
Matches a regular expression against `data`. \

View file

@ -144,6 +144,9 @@ func evaluate() -> bool:
logger.warn("Can't determine if data contains values as data is not of type String or StringName")
continue
# Set 'minimum_matches' to the amount of values if set to '-1'
if rule["minimum_matches"] == -1: rule["minimum_matches"] = rule["values"].size()
var successes: int = 0
for value in rule["values"]:
if data.contains(value):
@ -277,7 +280,7 @@ func has_values(values: Array) -> CoreValidationSingle:
rules.append({ "type": CoreTypes.ValidationType.HAS_VALUES, "values": values })
return self
## Ensures that [param data] contains at least <[code]minimum_matches[/code]> values.[br]
## Ensures that [param data] contains at least <[code]minimum_matches[/code]> (or all if set to [code]-1[/code]) values.[br]
## Applies to [String] & [StringName].
func contains(values: Array[String], minimum_matches: int = 1) -> CoreValidationSingle:
rules.append({ "type": CoreTypes.ValidationType.HAS_VALUES, "values": values, "minimum_matches": minimum_matches })