Sha256: 1de72d8f92f7efc4c999e81cacb0d74bbe23ece7191e00feb2cac6f6cad1b503

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Jekyll
  class IcalTag
    class CalendarLimiter
      def initialize(parser, options = {})
        @parser = parser
        @options = options
      end

      def events
        case
        when options[:only] == :future
          now = Time.now
          parser.events.select do |event|
            event.dtstart.to_time >= now
          end
        when options[:only] == :past
          now = Time.now
          parser.events.select do |event|
            event.dtstart.to_time < now
          end
        when options[:reverse]
          parser.events.reverse
        when options[:after_date]
          parser.events.select do |event|
            event.dtstart.to_time >= options[:after_date]
          end
        when options[:before_date]
          parser.events.select do |event|
            event.dtstart.to_time < options[:before_date]
          end
        else
          parser.events
        end
      end

      private

      attr_reader :parser, :options
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-ical-tag-1.0.2 lib/jekyll-ical-tag/calendar_limiter.rb