attribute.rb 983 B

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