diff options
author | Lars Henrik Mai <lars.mai@kontinui.de> | 2014-09-21 18:18:21 +0200 |
---|---|---|
committer | Lars Henrik Mai <lars.mai@kontinui.de> | 2014-09-21 18:24:51 +0200 |
commit | 0740cac0afa46fbc87062eef7003ff653bd5208a (patch) | |
tree | ff47df8d43aa2f4b2fb43f3dc103f4c1f739c603 /lib/sublab_calendar/event.rb | |
parent | 1955959b3bbd997a6a7f585f0293a295c019c935 (diff) |
make Event and Occurrence sortable and adds some convenience
Diffstat (limited to 'lib/sublab_calendar/event.rb')
-rw-r--r-- | lib/sublab_calendar/event.rb | 23 |
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) } |