Sha256: 2b0c2d848dab6107c412071c0c33468f9f5dfa630c7f194eef810a70b65029a1

Contents?: true

Size: 941 Bytes

Versions: 40

Compression:

Stored size: 941 Bytes

Contents

begin
  require 'icalendar'
rescue LoadError
  raise <<-ERR
The icalendar gem must be installed for ical output.
To install it:
$ [sudo] gem install icalendar -v"~>1.1.5"
  ERR
end

require 'date'
module Timetrap
  module Formatters
    class Ical
      include Icalendar
      def calendar
        @calendar ||= Calendar.new
      end

      def output
        calendar.to_ical
      end

      def initialize entries
        entries.each do |e|
          next unless e.end
          calendar.event do

            # hack around an issue in ical gem in ruby 1.9
            unless respond_to? :<=>
              def <=> other
                dtstart > other.dtstart ? 1 : 0
              end
            end

            dtstart DateTime.parse(e.start.to_s)
            dtend DateTime.parse(e.end.to_s)
            summary e.note
            description e.note
          end
        end
        calendar.publish
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
timetrap-1.8.6 lib/timetrap/formatters/ical.rb
timetrap-1.8.5 lib/timetrap/formatters/ical.rb
timetrap-1.8.4 lib/timetrap/formatters/ical.rb
timetrap-1.8.3 lib/timetrap/formatters/ical.rb
timetrap-1.8.3.beta2 lib/timetrap/formatters/ical.rb
timetrap-1.8.3.beta1 lib/timetrap/formatters/ical.rb
timetrap-1.8.2 lib/timetrap/formatters/ical.rb
timetrap-1.8.1 lib/timetrap/formatters/ical.rb
timetrap-1.8.0 lib/timetrap/formatters/ical.rb
timetrap-1.7.10 lib/timetrap/formatters/ical.rb
timetrap-1.7.9 lib/timetrap/formatters/ical.rb
timetrap-1.7.8 lib/timetrap/formatters/ical.rb
timetrap-1.7.7 lib/timetrap/formatters/ical.rb
timetrap-1.7.6 lib/timetrap/formatters/ical.rb
timetrap-1.7.5 lib/timetrap/formatters/ical.rb
timetrap-1.7.4 lib/timetrap/formatters/ical.rb
timetrap-1.7.3 lib/timetrap/formatters/ical.rb
timetrap-1.7.2 lib/timetrap/formatters/ical.rb
timetrap-1.7.1 lib/timetrap/formatters/ical.rb
timetrap-1.7.0 lib/timetrap/formatters/ical.rb