From a7132e54bd91db1ae86207fbd2a7abc27a456469 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Tue, 24 Dec 2019 15:07:01 +0100 Subject: [PATCH] Add selector methods Signed-off-by: Knut Ahlers --- unit.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/unit.go b/unit.go index 3230594..b66b70c 100644 --- a/unit.go +++ b/unit.go @@ -36,3 +36,24 @@ func (r *RawBlock) UnmarshalSII(in []byte) error { type Unit struct { Entries []Block } + +func (u Unit) BlocksByClass(class string) []Block { + var out []Block + + for _, b := range u.Entries { + if b.Class() == class { + out = append(out, b) + } + } + + return out +} + +func (u Unit) BlockByName(name string) Block { + for _, b := range u.Entries { + if b.Name() == name { + return b + } + } + return nil +}