1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package approve_former
- import "strings"
- type Or struct {
- childNodes []Node
- }
- func NewOr(childNodes ...Node) *Or {
- return &Or{
- childNodes: childNodes,
- }
- }
- func (or *Or) GetDepends() string {
- var depends string
- for _, childNode := range or.childNodes {
- if depends == "" {
- depends = childNode.GetDepends()
- } else {
- depends = depends + " && " + childNode.GetDepends()
- }
- }
- return depends
- }
- 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) Render(upperNode Node) (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
- }
|