# frozen_string_literal: true module TimeBoss class Calendar module Support module Translatable PERIODS = %w[day week month quarter half year] PERIODS.each do |period| periods = period.pluralize define_method(periods) { calendar.send("#{periods}_for", self) } define_method(period) do entries = send(periods) return nil unless entries.length == 1 entries.first end end # # i hate this # ### Days # @!method days # Get a list of days that fall within this unit. # @return [Array] # @!method day # Get the day this unit represents. # Returns nil if no single day can be identified. # @return [Array, nil] ### Weeks # @!method weeks # Get a list of weeks that fall within this unit. # @return [Array] # @!method week # Get the week this unit represents. # Returns nil if no single week can be identified. # @return [Array, nil] ### Months # @!method months # Get a list of months that fall within this unit. # @return [Array] # @!method month # Get the month this unit represents. # Returns nil if no single month can be identified. # @return [Array, nil] ### Quarters # @!method quarters # Get a list of quarters that fall within this unit. # @return [Array] # @!method quarter # Get the quarter this unit represents. # Returns nil if no single quarter can be identified. # @return [Array, nil] ### Halves # @!method halves # Get a list of halves that fall within this unit. # @return [Array] # @!method half # Get the half this unit represents. # Returns nil if no single half can be identified. # @return [Array, nil] ### Years # @!method years # Get a list of years that fall within this unit. # @return [Array] # @!method year # Get the year this unit represents. # Returns nil if no single year can be identified. # @return [Array, nil] end end end end