attribute.rb 898 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Units < SimpleDelegator
  3. class Attribute
  4. attr_accessor :from, :to, :optional
  5. # Checks if the attribute will be provided by one or more Units.
  6. #
  7. # @example
  8. # attribute.will_be_provided?
  9. # # => true
  10. #
  11. # @return [Boolean]
  12. def will_be_provided?
  13. !from.nil?
  14. end
  15. # Checks if the attribute will be used by one or more Units.
  16. #
  17. # @example
  18. # attribute.will_be_used?
  19. # # => true
  20. #
  21. # @return [Boolean]
  22. def will_be_used?
  23. till.present?
  24. end
  25. def optional?
  26. to.nil? && !optional.nil?
  27. end
  28. def cleanup?(index)
  29. return true if !will_be_used?
  30. till <= index
  31. end
  32. def available?(index)
  33. index.between?(from, till)
  34. end
  35. def till
  36. [to, optional].compact.max
  37. end
  38. end
  39. end