rag

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 2 Imported by: 1

README

Rag

Provides a tag filtering language to filter tagged text.

Tag filtering allows building developer tools with easy filtering capabilities in mind.

Usage

The core of rag is TagFilter, a data structure that can accept or reject a string slice called "input tags". Through this README, TagFilter will refer to the string provided to rag.Parse to build a TagFilter.

There are 3 main functions in rag:

  • rag.Parse which converts a string, such as foo,_untagged into a TagFilter
  • TagFilter.Select which returns true if the filter decided that the input tags are accepted and as such, the data tagged with the input tags should be preserved and not filtered out
  • TagFilter.Reject, opposite of Select

Filtering Language

The TagFilter _all will ensure nothing is filtered out, that is Select always returns true.

If a TagFilter is not set to _all, it should contain a list of tags, separated by comma. If the input tags have at least one of the tags listed in TagFilter, Select will return true. A tag can be prefixed with a modifier, which is either + or -.

A tag prefixed with + must be present on the input tags. If multiple tags are prefixed with + they must all be present in the input tags. This means that the input tags must include all tags prefixed with a + and at least one unprefixed tag (if any present in the TagFilter).

If a tag is prefixed with -, it must be absent from the input tags. Every empty list of input tags is rejected unless the keyword _untagged is present in input tags.

Usage

package main

import (
	"github.com/thehungry-dev/rag"
)

func main() {
  filter := rag.Parse("foo,tag1,_untagged,+bar,+baz")

  var selected bool

  // selected is true
  selected = filter.Select([]string{"bar","foo","baz"})

  // selected is false
  selected = filter.Select([]string{"foo","baz"})
}

Examples

foo,tag1,_untagged,+bar,+baz

Select will return true if the input tags satisfy all the following conditions:

  • Have at least one of: foo or tag1
  • Have both: bar and baz

Alternatively the input tags could be empty.

foo,tag1,+bar,-baz

Select will return true if the input tags satisfy all the following conditions:

  • Have at least one of: foo or tag1
  • Have: bar
  • Not have: baz

Development

Testing

Requirements:

  • make

Documentation

Overview

Package rag provides a tag filtering language for tagged text

Index

Constants

View Source
const AllTagsKeyword = "_all"
View Source
const TagExcludedToken = "-"
View Source
const TagRequiredToken = "+"
View Source
const TagSeparator = ","
View Source
const UntaggedKeyword = "_untagged"

Variables

This section is empty.

Functions

This section is empty.

Types

type TagFilter

type TagFilter struct {
	// contains filtered or unexported fields
}
var FilterNothing *TagFilter

Filter for which Select always returns true

func Parse

func Parse(filterText string) *TagFilter

Converts rag language into a filtering object

func (*TagFilter) IsExcludedTag

func (tagFilter *TagFilter) IsExcludedTag(tag string) bool

func (*TagFilter) IsRequiredOneOfTag

func (tagFilter *TagFilter) IsRequiredOneOfTag(tag string) bool

func (*TagFilter) IsRequiredTag

func (tagFilter *TagFilter) IsRequiredTag(tag string) bool

func (*TagFilter) IsUntaggedOnly

func (tagFilter *TagFilter) IsUntaggedOnly() bool

func (*TagFilter) Reject

func (tagFilter *TagFilter) Reject(inputTags []string) bool

func (*TagFilter) Select

func (tagFilter *TagFilter) Select(inputTags []string) bool

func (*TagFilter) String

func (tagFilter *TagFilter) String() string

Directories

Path Synopsis
internal
set
pkg
ctrls
Package ctrls provides building blocks to generate sample data for a test environment
Package ctrls provides building blocks to generate sample data for a test environment

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL