github.com/blend/go-sdk@v1.20220411.3/profanity/rule_specs.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package profanity 9 10 import "strings" 11 12 // RuleSpecFile is a map of string rule id to rule item. 13 // 14 // It is the format for profanity rule files. 15 type RuleSpecFile map[string]RuleSpec 16 17 // Rules returns the 18 func (rsf RuleSpecFile) Rules() []RuleSpec { 19 var rules []RuleSpec 20 for id, rule := range rsf { 21 rule.ID = id 22 rules = append(rules, rule) 23 } 24 return rules 25 } 26 27 // String implements fmt.Stringer. 28 func (rsf RuleSpecFile) String() string { 29 if len(rsf) == 0 { 30 return "<empty>" 31 } 32 var output []string 33 for _, rule := range rsf.Rules() { 34 output = append(output, rule.String()) 35 } 36 return strings.Join(output, "\n") 37 }