module Timely::DateRangeValidityModule

Public Class Methods

included(base) click to toggle source
# File lib/timely/rails/date_range_validity_module.rb, line 5
def self.included(base)
  base.class_eval do
    validates :from, :to, presence: true
  end
end

Public Instance Methods

correctness_of_date_range() click to toggle source
# File lib/timely/rails/date_range_validity_module.rb, line 15
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
valid_on?(date) click to toggle source
# File lib/timely/rails/date_range_validity_module.rb, line 25
def valid_on?(date)
  validity_range.include?(date)
end
validity_range() click to toggle source
# File lib/timely/rails/date_range_validity_module.rb, line 11
def validity_range
  (from..to)
end
validity_range_to_s() click to toggle source
# File lib/timely/rails/date_range_validity_module.rb, line 21
def validity_range_to_s
  "#{from.to_s(:short)} ~ #{to.to_s(:short)}"
end