Sha256: 9307e8e9d869f15a6d2361f6623be1c860cea3d876cf85afc675bd8642bf5287

Contents?: true

Size: 823 Bytes

Versions: 3

Compression:

Stored size: 823 Bytes

Contents

module Almanack
  module Representation
    class IcalFeed
      attr_reader :calendar

      def initialize(calendar)
        @calendar = calendar
      end

      def ical
        @ical ||= ical_calendar
      end

      def to_s
        ical.to_ical
      end

      def self.from(calendar)
        self.new(calendar)
      end

      private

      def events
        calendar.events_between(now..lookahead)
      end

      def ical_calendar
        events.each_with_object(Icalendar::Calendar.new) do |event, calendar|
          calendar.add_event ical_event_for(event)
        end
      end

      def ical_event_for(event)
        BuiltIcalEvent.for(event)
      end

      def lookahead
        now + calendar.feed_lookahead * ONE_DAY
      end

      def now
        @now ||= Time.now
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
almanack-1.3.1 lib/almanack/representation/ical_feed.rb
almanack-1.3.0 lib/almanack/representation/ical_feed.rb
almanack-1.3.0.rc1 lib/almanack/representation/ical_feed.rb