summaryrefslogtreecommitdiff
path: root/lib/sublab_calendar/occurrence.rb
blob: 085a814c82f3ef4632a858a373d77072a551bc1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module SublabCalendar

  class Occurrence < SimpleDelegator

    attr_reader :event

    def initialize(occurrence, event)
      @event = event
      super(occurrence)
    end

    def to_h
      {
        summary: summary,
        start:   start_time,
        end:     end_time
      }
    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 ==(o)
      o.class == self.class && o.state == state
    end
    alias_method :eql?, :==

    def summary
      event.summary
    end

    def description
      event.description
    end

    def dtstart
      start_time.to_datetime
    end

    protected

    def state
      [event.uid, start_time, end_time]
    end

  end

end