diff --git a/every_of.go b/every_of.go new file mode 100644 index 0000000..e93f233 --- /dev/null +++ b/every_of.go @@ -0,0 +1,28 @@ +package glob + +// EveryOf represents a collection of globs +type EveryOf struct { + Globs Globs +} + +// NewEveryOf returns a new EveryOf from a list of globs +func NewEveryOf(g ...Glob) EveryOf { + return EveryOf{Globs(g)} +} + +// Add adds a glob to the EveryOf collection +func (a *EveryOf) Add(g Glob) { + a.Globs = append(a.Globs, g) +} + +// Match checks every glob until one doesn't matches returning false. +// If every glob matches it returns true. +func (a EveryOf) Match(s string) bool { + for _, m := range a.Globs { + if !m.Match(s) { + return false + } + } + + return true +}