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
3 4 5 6 7 |
# File 'lib/timely/rails/date_range_validity_module.rb', line 3 def self.included(base) base.class_eval do validates :from, :to, :presence => true end end |
Instance Method Details
#correctness_of_date_range ⇒ Object
13 14 15 16 17 |
# File 'lib/timely/rails/date_range_validity_module.rb', line 13 def correctness_of_date_range if (from.present? && to.present?) errors.add(:base, "Invalid Date Range. From date should be less than or equal to To date") if from > to end end |
#valid_on?(date) ⇒ Boolean
23 24 25 |
# File 'lib/timely/rails/date_range_validity_module.rb', line 23 def valid_on?(date) validity_range.include?(date) end |
#validity_range ⇒ Object
9 10 11 |
# File 'lib/timely/rails/date_range_validity_module.rb', line 9 def validity_range (from .. to) end |
#validity_range_to_s ⇒ Object
19 20 21 |
# File 'lib/timely/rails/date_range_validity_module.rb', line 19 def validity_range_to_s "#{from.to_s(:short)} ~ #{to.to_s(:short)}" end |