module SublabCalendar class Event < SimpleDelegator def to_h { summary: summary, start: dtstart, end: dtend } end def to_json(*args) to_h.to_json(*args) end def to_s "<#{self.class} #{self.to_h}>" end alias_method :inspect, :to_s def <=>(other) self.dtstart.to_datetime <=> other.dtstart.to_datetime end def ==(other) self.uid == other.uid end alias_method :eql?, :== def recurring? ! rrule.empty? end def all_day? # all day events do not have a time, and get parsed to a Icalendar::Values:Date class dtstart.is_a? Icalendar::Values::Date end def occurrences_this_month return nil unless recurring? occurrences_between(*this_month).map {|occ| Occurrence.new(occ, self) } end private def this_month [Date.today.beginning_of_month, Date.today.next_month.beginning_of_month] end end end