Sha256: b896f8f874d24fd9f8fe71abf6ce24d8111954c0ce1676112bd1d043d097da5d

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require "active_support"
require "active_support/core_ext"
require "google/apis/calendar_v3"

require "holidays_from_google_calendar/cache"
require "holidays_from_google_calendar/cache_unit"
require "holidays_from_google_calendar/client"
require "holidays_from_google_calendar/configuration"
require "holidays_from_google_calendar/holiday"
require "holidays_from_google_calendar/version"

module HolidaysFromGoogleCalendar
  class Holidays
    def initialize
      @configuration = Configuration.new
      yield @configuration
      @client = Client.new(@configuration)
    end

    def in_year(date)
      @client.retrieve(
        date_min: date.beginning_of_year,
        date_max: date.end_of_year + 1.day
      )
    end

    def in_month(date)
      @client.retrieve(
        date_min: date.beginning_of_month,
        date_max: date.end_of_month + 1.day
      )
    end

    def holiday?(date)
      return true if date.wday.in?([0, 6]) # If Sunday or Saturday
      @client.retrieve(date_min: date, date_max: date + 1.day).size > 0
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
holidays_from_google_calendar-0.4.1 lib/holidays_from_google_calendar.rb
holidays_from_google_calendar-0.4.0 lib/holidays_from_google_calendar.rb