module SublabCalendar class Calendar attr_reader :calendar def initialize(ical) @calendar = Icalendar.parse(ical).first end def self.load(url=URL) request = HTTPI::Request.new request.url = URL request.auth.digest(USER, PASS) request.auth.ssl.verify_mode = :none response = HTTPI.get(request) ical = response.body new(ical) end def events calendar.events.map(&method(:readable)) end def future calendar.events.select {|ev| ev.dtstart >= DateTime.now}.map(&method(:readable)) end def past calendar.events.select {|ev| ev.dtstart < DateTime.now}.map(&method(:readable)) end def recurring events.select(&:"recurring?") end def next(count=1) future.take(count) end def readable(event) SublabCalendar::Event.new(event) end end end