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.15.2 lib/timetrap/formatters/ical.rb
timetrap-1.15.1 lib/timetrap/formatters/ical.rb
timetrap-1.14.3 lib/timetrap/formatters/ical.rb
timetrap-1.15.0 lib/timetrap/formatters/ical.rb
timetrap-1.14.2 lib/timetrap/formatters/ical.rb
timetrap-1.14.1 lib/timetrap/formatters/ical.rb
timetrap-1.14.0 lib/timetrap/formatters/ical.rb
timetrap-1.13.0 lib/timetrap/formatters/ical.rb
timetrap-1.12.0 lib/timetrap/formatters/ical.rb
timetrap-1.11.0 lib/timetrap/formatters/ical.rb
timetrap-1.10.0 lib/timetrap/formatters/ical.rb
timetrap-1.9.0 lib/timetrap/formatters/ical.rb
timetrap-1.8.14 lib/timetrap/formatters/ical.rb
timetrap-1.8.13 lib/timetrap/formatters/ical.rb
timetrap-1.8.12 lib/timetrap/formatters/ical.rb
timetrap-1.8.11 lib/timetrap/formatters/ical.rb
timetrap-1.8.10 lib/timetrap/formatters/ical.rb
timetrap-1.8.9 lib/timetrap/formatters/ical.rb
timetrap-1.8.8 lib/timetrap/formatters/ical.rb
timetrap-1.8.7 lib/timetrap/formatters/ical.rb