A small, lean customizable ruby library to determine work days.
WorkCalendar.configure do |c|
c.weekdays = %i[sat sun mon tue wed]
c.holidays = [Date.new(2016, 8, 8)]
end
WorkCalendar.active?(DATE)
WorkCalendar.days_before(x, DATE)
WorkCalendar.days_after(x, DATE)
WorkCalendar.between(FROM_DATE, TO_DATE)
I was shooting for something that was super lean and super simple. So I test drove it according to the requirements provided. I started out with the active?
method since that was the core of the implementation; all other behaviour relies on it somehow. Once completed I was able to use active?
to implement the rest of the required behaviour.
-
I decided to use
OpenStruct
instead of a class to maintain the custom configuration because it helped make the code look simpler and shorter. All behaviour was heavily tested (Test Driven!) and using a class overOpenStruct
made no difference in the behaviour. In the end I choseOpenStruct
for the simplicity. -
I added a method
reset_to_default_config!
as a means to avoid test pollution in my test suite. I didn't feel the need to unit test this method because the tests would fail pretty loudly anyway without a way to clear any customizations.
-
clone the repo:
git clone https://github.com/sufyanadam/work_calendar
-
cd /path/to/repo-you-just-cloned
-
bundle
-
rspec