lib/models/ical_cache.rb
# Return the next iCal event after the current time
Return the next iCal event after the current time
Return the next iCal event after the current time
def next_event(keyword = nil)
    nearest_event = nil
    nearest_seconds_until = nil
    upcoming_events.each do |event|
      event = (event.occurrences({:starting => DateTime.now, :count => 1})).first
      if event and event.start_time > DateTime.now
        seconds_until = ((event.start_time - DateTime.now) * 24 * 60 * 60).to_i
        if keyword and event.summary.strip.downcase.include? keyword.downcase
          if !nearest_seconds_until
            nearest_seconds_until = seconds_until
            nearest_event = event
          elsif seconds_until < nearest_seconds_until
            nearest_seconds_until = seconds_until
            nearest_event = event
          end
        elsif !keyword
          if !nearest_seconds_until
            nearest_seconds_until = seconds_until
            nearest_event = event
          elsif seconds_until < nearest_seconds_until
            nearest_seconds_until = seconds_until
            nearest_event = event
          end
        end
      end
    end
    nearest_event
  end
def next_event ( keyword = nil ) nearest_event = nil nearest_seconds_until = nil upcoming_events . each do | event | event = ( event . occurrences ( { :starting => DateTime . now , :count => 1 } ) ) . first if event and event . start_time > DateTime . now seconds_until = ( ( event . start_time - DateTime . now ) * 24 * 60 * 60 ) . to_i if keyword and event . summary . strip . downcase . include? keyword . downcase if ! nearest_seconds_until nearest_seconds_until = seconds_until nearest_event = event elsif seconds_until < nearest_seconds_until nearest_seconds_until = seconds_until nearest_event = event end elsif ! keyword if ! nearest_seconds_until nearest_seconds_until = seconds_until nearest_event = event elsif seconds_until < nearest_seconds_until nearest_seconds_until = seconds_until nearest_event = event end end end end nearest_event end
Return the next iCal event after the current time
Return the next iCal event after the current time
# Grab the next occurrence for the event
keyword