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