Class: SexyValidations::Validators::Date

Inherits:
Object
  • Object
show all
Defined in:
lib/sexy_validations/validators/date.rb

Class Method Summary collapse

Class Method Details

.validate(record, attribute, value, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sexy_validations/validators/date.rb', line 5

def self.validate(record, attribute, value, options)
  return unless value
     
  if value.is_a?(::Date) || value.is_a?(::Time)
    if options.is_a?(Hash)
      min = options[:within].min
      if value < min
        record.errors.add(attribute, "zu früh (frühestens #{min})")
      end

      max = options[:within].max
      if value > max
        record.errors.add(attribute, "zu spät (spätestens #{max})")
      end
    end
  else
    record.errors.add(attribute, "ungültig")
  end
end