123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package approve_former
- import "strings"
- type Or struct {
- childNodes []Noder
- }
- func NewOr(childNodes ...Noder) *Or {
- return &Or{
- childNodes: childNodes,
- }
- }
- func (or *Or) GetWhen() string {
- var when string
- for _, childNode := range or.childNodes {
- if when == "" {
- when = "(" + childNode.GetWhen() + ")"
- } else {
- when = when + " || " + "(" + childNode.GetWhen() + ")"
- }
- }
- return when
- }
- func (or *Or) AddNodes(childNodes ...Noder) *Or {
- if childNodes == nil || len(childNodes) == 0 {
- or.childNodes = append(or.childNodes, childNodes...)
- }
- return or
- }
- func (or *Or) Render(upperNode Noder) (string, error) {
- var content string
- for _, childNode := range or.childNodes {
- childNodeContent, err := childNode.Render(upperNode)
- if err != nil {
- return "", err
- }
- content = content + childNodeContent + "\n"
- }
- content = strings.TrimSuffix(content, "\n")
- return content, nil
- }
|