module SublabCalendar class Event < SimpleDelegator BASIC_ATTRIBUTES = [:summary, :dtstart, :dtend] def to_h BASIC_ATTRIBUTES.inject({}) {|hsh, attr| hsh[attr] = send(attr).to_s; hsh } end def to_json(*args) to_h.to_json(*args) end def to_s "<#{self.class} #{self.to_h}>" end def inspect to_s end def recurring? ! rrule.empty? 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