class BatchNumberValidator
Constants
- FORMAT
- MAX_LENGTH
- MIN_LENGTH
Public Instance Methods
Source
# File app/validators/batch_number_validator.rb, line 8 def validate_each(record, attribute, value) if value.blank? record.errors.add(attribute, :blank) elsif value.length < MIN_LENGTH record.errors.add(attribute, :too_short, count: MIN_LENGTH) elsif value.length > MAX_LENGTH record.errors.add(attribute, :too_long, count: MAX_LENGTH) elsif value !~ FORMAT record.errors.add(attribute, :invalid) end end