or.go 992 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package approve_former
  2. import "strings"
  3. type Or struct {
  4. childNodes []Node
  5. }
  6. func NewOr(childNodes ...Node) *Or {
  7. return &Or{
  8. childNodes: childNodes,
  9. }
  10. }
  11. func (or *Or) GetDepends() string {
  12. var depends string
  13. for _, childNode := range or.childNodes {
  14. if depends == "" {
  15. depends = childNode.GetDepends()
  16. } else {
  17. depends = depends + " && " + childNode.GetDepends()
  18. }
  19. }
  20. return depends
  21. }
  22. func (or *Or) GetWhen() string {
  23. var when string
  24. for _, childNode := range or.childNodes {
  25. if when == "" {
  26. when = "(" + childNode.GetWhen() + ")"
  27. } else {
  28. when = when + " || " + "(" + childNode.GetWhen() + ")"
  29. }
  30. }
  31. return when
  32. }
  33. func (or *Or) Render(upperNode Node) (string, error) {
  34. var content string
  35. for _, childNode := range or.childNodes {
  36. childNodeContent, err := childNode.Render(upperNode)
  37. if err != nil {
  38. return "", err
  39. }
  40. content = content + childNodeContent + "\n"
  41. }
  42. content = strings.TrimSuffix(content, "\n")
  43. return content, nil
  44. }