Sha256: 769dc6afe4726a1386ee8127e8cbdcecdf6351aa8ff0ad882ad744c7a8bd58d0

Contents?: true

Size: 693 Bytes

Versions: 12

Compression:

Stored size: 693 Bytes

Contents

# encoding: utf-8
module SexyValidations
  module Validators
    class Date
      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
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
sexy_validations-0.5.4 lib/sexy_validations/validators/date.rb
sexy_validations-0.5.3 lib/sexy_validations/validators/date.rb
sexy_validations-0.5.2 lib/sexy_validations/validators/date.rb
sexy_validations-0.5.1 lib/sexy_validations/validators/date.rb
sexy_validations-0.5.0 lib/sexy_validations/validators/date.rb
sexy_validations-0.4.3 lib/sexy_validations/validators/date.rb
sexy_validations-0.4.2 lib/sexy_validations/validators/date.rb
sexy_validations-0.4.1 lib/sexy_validations/validators/date.rb
sexy_validations-0.4.0 lib/sexy_validations/validators/date.rb
sexy_validations-0.3.1 lib/sexy_validations/validators/date.rb
sexy_validations-0.3.0 lib/sexy_validations/validators/date.rb
sexy_validations-0.2.2 lib/sexy_validations/validators/date.rb