module BankHolidays

Public Class Methods

all() click to toggle source

Get a list of all bank holidays

# File lib/bankholidays.rb, line 9
def self.all    
  self.get_dates
end
next() click to toggle source

Get the next bank holiday

# File lib/bankholidays.rb, line 14
def self.next
  self.get_dates.reject { |x| x[:date] < Date.today }.first
end

Private Class Methods

get_dates() click to toggle source
# File lib/bankholidays.rb, line 20
def self.get_dates
  dates = []
  year = Date.today.year
  years = (year..(year + 10)).to_a

  years.each do |y|
    res = HTTParty.get "https://www.gov.uk/bank-holidays/england-and-wales-#{y}.ics"
    break if res.code == 404
    ics = Icalendar.parse( res )
    cal = ics.first
    cal.events.each do |e|
      dates << { :date => e.dtstart, :name => e.summary }
    end
  end
  
  dates
end