Class: NationalGovernmentOrganizationHoliday::Duration
- Inherits:
-
ActiveSupport::Duration
- Object
- ActiveSupport::Duration
- NationalGovernmentOrganizationHoliday::Duration
- Defined in:
- lib/national_government_organization_holiday/duration.rb
Constant Summary collapse
- MIN_PLUS_DAYS =
1
- MAX_PLUS_DAYS =
7
Instance Method Summary collapse
-
#initialize(plus_days) ⇒ Duration
constructor
A new instance of Duration.
- #since(beginning_day) ⇒ Object
Constructor Details
#initialize(plus_days) ⇒ Duration
Returns a new instance of Duration.
11 12 13 14 15 16 17 |
# File 'lib/national_government_organization_holiday/duration.rb', line 11 def initialize(plus_days) raise TypeError unless plus_days.is_a?(Integer) raise ArgumentError unless (MIN_PLUS_DAYS..MAX_PLUS_DAYS).cover?(plus_days) # See: https://github.com/rails/rails/blob/v7.0.4.3/activesupport/lib/active_support/duration.rb#L166-L167 super(plus_days * SECONDS_PER_DAY, { days: plus_days }, true) end |
Instance Method Details
#since(beginning_day) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/national_government_organization_holiday/duration.rb', line 20 def since(beginning_day) weekdays = [] plus_days = parts[:days] max_day = beginning_day.next_month beginning_day.next.upto(max_day) do |next_day| weekdays << next_day if Value.new(next_day).on_weekday? break if weekdays.count == plus_days end weekdays.last end |