Sha256: 58bccab10531595fbbd624fd96b53d56f666395e11798ac1f65205cfcd46e2b5

Contents?: true

Size: 857 Bytes

Versions: 1

Compression:

Stored size: 857 Bytes

Contents

module Repeatable
  module Expression
    class RangeInYear < Base
      def initialize(start_month:, end_month: start_month, start_day: 0, end_day: 0)
        @start_month = start_month
        @end_month = end_month
        @start_day = start_day
        @end_day = end_day
      end

      def include?(date)
        months_include?(date) || start_month_include?(date) || end_month_include?(date)
      end

      private

      attr_reader :start_month, :end_month, :start_day, :end_day

      def months_include?(date)
        date.month > start_month && date.month < end_month
      end

      def start_month_include?(date)
        date.month == start_month && (start_day == 0 || date.day >= start_day)
      end

      def end_month_include?(date)
        date.month == end_month && (end_day == 0 || date.day <= end_day)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
repeatable-0.1.0 lib/repeatable/expression/range_in_year.rb