Sha256: d9039dd02eefd92db4eeb3e3dc1cc709144fc325be2fc8d529ff1034e0e2617a

Contents?: true

Size: 811 Bytes

Versions: 6

Compression:

Stored size: 811 Bytes

Contents

# frozen_string_literal: true

require "yaml"

module RussianWorkdays
  DATES = YAML.load_file(File.join(__dir__, "dates.yml")).freeze

  class Day
    def initialize(date)
      @date = date
      raise ArgumentError, "Must be a Date object" unless @date.is_a?(::Date)
      raise ArgumentError, "Data missing for that year" unless DATES.key?(@date.year)
    end

    def holiday?
      !preholiday? && (weekend? || DATES[@date.year][:holidays].include?(@date))
    end

    def preholiday?
      DATES[@date.year][:preholidays].include?(@date)
    end

    def work?
      !holiday?
    end

    def type
      return :holiday if holiday?
      return :preholiday if preholiday?
      return :work if work?
    end

    private

      def weekend?
        @date.sunday? || @date.saturday?
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
russian_workdays-2.6.0 lib/russian_workdays/day.rb
russian_workdays-2.5.0 lib/russian_workdays/day.rb
russian_workdays-2.4.0 lib/russian_workdays/day.rb
russian_workdays-2.3.0 lib/russian_workdays/day.rb
russian_workdays-2.1.0 lib/russian_workdays/day.rb
russian_workdays-2.0.0 lib/russian_workdays/day.rb