class HolidaysFromGoogleCalendar::CacheUnit

Attributes

date_max[R]
date_min[R]
holidays[R]

Public Class Methods

new(holidays, date_min, date_max) click to toggle source
# File lib/holidays_from_google_calendar/cache_unit.rb, line 5
def initialize(holidays, date_min, date_max)
  @holidays = holidays
  @date_min = date_min
  @date_max = date_max
end

Public Instance Methods

combine(other) click to toggle source
# File lib/holidays_from_google_calendar/cache_unit.rb, line 28
def combine(other)
  return unless overlapped?(other)
  @date_min = [@date_min, other.date_min].min
  @date_max = [@date_max, other.date_max].max
  @holidays =
    @holidays.concat(other.holidays).uniq.sort { |a, b| a.date <=> b.date }
end
include?(date_min, date_max) click to toggle source
# File lib/holidays_from_google_calendar/cache_unit.rb, line 15
def include?(date_min, date_max)
  [date_min, date_max].all? { |e| @date_min <= e && e <= @date_max }
end
overlapped?(other) click to toggle source
# File lib/holidays_from_google_calendar/cache_unit.rb, line 23
def overlapped?(other)
  (@date_min <= other.date_max && other.date_min <= @date_max + 1.day) ||
    (other.date_min <= @date_max && @date_min <= other.date_max + 1.day)
end
retrieve(date_min, date_max) click to toggle source
# File lib/holidays_from_google_calendar/cache_unit.rb, line 19
def retrieve(date_min, date_max)
  @holidays.select { |e| date_min <= e.date && e.date <= date_max }
end
size() click to toggle source
# File lib/holidays_from_google_calendar/cache_unit.rb, line 11
def size
  @holidays.size
end