From c03c40d385df92d8c02437b557056ae20a085a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Gim=C3=A9nez?= Date: Mon, 6 May 2024 10:33:28 +0900 Subject: [PATCH] oops --- pkg/nip/rule.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/nip/rule.go b/pkg/nip/rule.go index c49aee4..c93f995 100644 --- a/pkg/nip/rule.go +++ b/pkg/nip/rule.go @@ -40,6 +40,28 @@ type Rule struct { type RuleResult int type Rules []Rule +func (r Rules) EvaluateAll(it data.Item) (Rule, RuleResult) { + bestMatch := RuleResultNoMatch + bestMatchingRule := Rule{} + for _, rule := range r { + if rule.Enabled { + result, err := rule.Evaluate(it) + if err != nil { + continue + } + if result == RuleResultFullMatch { + return rule, result + } + if result == RuleResultPartial { + bestMatch = result + bestMatchingRule = rule + } + } + } + + return bestMatchingRule, bestMatch +} + var fixedPropsList = map[string]int{"type": 0, "quality": 0, "class": 0, "name": 0, "flag": 0, "color": 0} func NewRule(rawRule string, filename string, lineNumber int) (Rule, error) {