Module: Timely::DateRangeValidityModule
- Defined in:
- lib/timely/rails/date_range_validity_module.rb
Class Method Summary collapse
Instance Method Summary collapse
- #correctness_of_date_range ⇒ Object
- #valid_on?(date) ⇒ Boolean
- #validity_range ⇒ Object
- #validity_range_to_s ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 |
# 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 |
Instance Method Details
#correctness_of_date_range ⇒ Object
15 16 17 18 19 |
# 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) ⇒ Boolean
25 26 27 |
# File 'lib/timely/rails/date_range_validity_module.rb', line 25 def valid_on?(date) validity_range.include?(date) end |
#validity_range ⇒ Object
11 12 13 |
# File 'lib/timely/rails/date_range_validity_module.rb', line 11 def validity_range (from..to) end |
#validity_range_to_s ⇒ Object
21 22 23 |
# 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 |