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.rb23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/sublab_calendar/event.rb b/lib/sublab_calendar/event.rb
index d350d51..e5042d8 100644
--- a/lib/sublab_calendar/event.rb
+++ b/lib/sublab_calendar/event.rb
@@ -2,10 +2,12 @@ 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 }
+ {
+ summary: summary,
+ start: dtstart,
+ end: dtend
+ }
end
def to_json(*args)
@@ -15,15 +17,26 @@ module SublabCalendar
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 inspect
- to_s
+ 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) }