aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/bank_holidays_cache.rb
blob: ce50663269a92110d735d6bb59043984277c4699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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