diff options
author | Alex Young <alex@bytemark.co.uk> | 2015-04-20 16:14:03 +0100 |
---|---|---|
committer | Alex Young <alex@bytemark.co.uk> | 2015-04-20 16:14:03 +0100 |
commit | 3e986ecfc544b94f329e35ae5b771f68ed27851a (patch) | |
tree | f2e32b811ae765c2481c9c64cbdfc91b91033016 /lib/mauve/bank_holidays_cache.rb | |
parent | 0a42bb136dc6ccbbf36500d4cc50441681178867 (diff) |
Pull the bank holidays cache out to its own class
Diffstat (limited to 'lib/mauve/bank_holidays_cache.rb')
-rw-r--r-- | lib/mauve/bank_holidays_cache.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/mauve/bank_holidays_cache.rb b/lib/mauve/bank_holidays_cache.rb new file mode 100644 index 0000000..ce50663 --- /dev/null +++ b/lib/mauve/bank_holidays_cache.rb @@ -0,0 +1,28 @@ +require 'mauve/calendar_interface' + +module Mauve + + class BankHolidaysCache + def initialize + @bank_holidays = [] + @last_checked_at = nil + end + + def bank_holidays + now = Time.now + # + # Update the bank holidays list hourly. + # + if @bank_holidays.nil? or + @last_checked_at.nil? or + @last_checked_at < (now - 1.hour) + + @bank_holidays = CalendarInterface.get_bank_holiday_list(now) + @last_checked_at = now + end + + @bank_holidays + end + end # class BankHolidaysCache + +end # module Mauve |