Return nip.Rule struct from Evaluate function in itemfilter (#14)
* Return Rule from Evaluate in itemfilter * Return Rule as the first argument
This commit is contained in:
committed by
GitHub
parent
d5d0f0a51f
commit
58b995842d
@@ -55,7 +55,8 @@ func (w *Watcher) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
d := w.gr.GetData()
|
d := w.gr.GetData()
|
||||||
for _, i := range d.Items.ByLocation(item.LocationGround) {
|
for _, i := range d.Items.ByLocation(item.LocationGround) {
|
||||||
if !itemfilter.Evaluate(i, w.rules) {
|
_, match := itemfilter.Evaluate(i, w.rules)
|
||||||
|
if !match {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/hectorgimenez/d2go/pkg/nip"
|
"github.com/hectorgimenez/d2go/pkg/nip"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Evaluate(i data.Item, rules []nip.Rule) bool {
|
func Evaluate(i data.Item, rules []nip.Rule) (nip.Rule, bool) {
|
||||||
for _, r := range rules {
|
for _, r := range rules {
|
||||||
if !evaluateGroups(i, r.Properties, checkProperty) {
|
if !evaluateGroups(i, r.Properties, checkProperty) {
|
||||||
// Properties not matching, skipping
|
// Properties not matching, skipping
|
||||||
@@ -17,15 +17,15 @@ func Evaluate(i data.Item, rules []nip.Rule) bool {
|
|||||||
|
|
||||||
// We can not check stats, item is not identified, but properties matching
|
// We can not check stats, item is not identified, but properties matching
|
||||||
if !i.Identified {
|
if !i.Identified {
|
||||||
return true
|
return nip.Rule{}, true
|
||||||
}
|
}
|
||||||
|
|
||||||
if evaluateGroups(i, r.Stats, checkStat) {
|
if evaluateGroups(i, r.Stats, checkStat) {
|
||||||
return true
|
return r, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return nip.Rule{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func evaluateGroups(i data.Item, groups []nip.Group, evalFunc func(i data.Item, prop nip.Comparable) bool) bool {
|
func evaluateGroups(i data.Item, groups []nip.Group, evalFunc func(i data.Item, prop nip.Comparable) bool) bool {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func TestEvaluate(t *testing.T) {
|
|||||||
rule, err := nip.ParseLine(tt.args.nipRule)
|
rule, err := nip.ParseLine(tt.args.nipRule)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if got := Evaluate(tt.args.i, []nip.Rule{rule}); got != tt.want {
|
if _, got := Evaluate(tt.args.i, []nip.Rule{rule}); got != tt.want {
|
||||||
t.Errorf("Evaluate() = %v, want %v", got, tt.want)
|
t.Errorf("Evaluate() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user