summaryrefslogtreecommitdiff
path: root/lib/sublab_calendar/event.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sublab_calendar/event.rb')
-rw-r--r--lib/sublab_calendar/event.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/sublab_calendar/event.rb b/lib/sublab_calendar/event.rb
new file mode 100644
index 0000000..d350d51
--- /dev/null
+++ b/lib/sublab_calendar/event.rb
@@ -0,0 +1,39 @@
+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