Sha256: 11b92200d0b98b9d1086a7cca0772b6c4c5427cb5ccba6a43551c23650dac5bb

Contents?: true

Size: 543 Bytes

Versions: 1

Compression:

Stored size: 543 Bytes

Contents

module Repeatable
  module Expression
    class WeekdayInMonth < Base
      def initialize(weekday:, count:)
        @weekday = weekday
        @count = count
      end

      def include?(date)
        day_matches?(date) && week_matches?(date)
      end

      private

      attr_reader :weekday, :count

      def day_matches?(date)
        date.wday == weekday
      end

      def week_matches?(date)
        week_in_month(date.day) == count
      end

      def week_in_month(day)
        ((day - 1) / 7) + 1
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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