Sha256: 8f0d706cce7b88bd88bc21255c318de14a44a448be0914c81b5537418e9d8ae1
Contents?: true
Size: 612 Bytes
Versions: 9
Compression:
Stored size: 612 Bytes
Contents
# frozen_string_literal: true module Timely module DateRangeValidityModule def self.included(base) base.class_eval do validates :from, :to, presence: true end end def validity_range (from..to) end def correctness_of_date_range return unless from.present? && to.present? && from > to errors.add(:base, 'Invalid Date Range. From date should be less than or equal to To date') end def validity_range_to_s "#{from.to_s(:short)} ~ #{to.to_s(:short)}" end def valid_on?(date) validity_range.include?(date) end end end
Version data entries
9 entries across 9 versions & 1 rubygems