Skip to content

Commit

Permalink
Move invariant check to initialise
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Morton committed Jun 8, 2020
1 parent 256303c commit d46c920
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/business/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def initialize(config)
set_extra_working_dates(config[:extra_working_dates])
set_working_days(config[:working_days])
set_holidays(config[:holidays])

unless (@holidays & @extra_working_dates).none?
raise ArgumentError, 'Holidays cannot be extra working dates'
end
end

# Return true if the date given is a business day (typically that means a
Expand Down Expand Up @@ -197,8 +201,6 @@ def parse_dates(dates)
# Internal method for assigning holidays from a calendar config.
def set_holidays(holidays)
@holidays = parse_dates(holidays)
return if (@holidays & @extra_working_dates).none?
raise ArgumentError, 'Holidays cannot be extra working dates'
end

def set_extra_working_dates(extra_working_dates)
Expand Down

0 comments on commit d46c920

Please sign in to comment.