Sha256: f5cf81ff1da9396aa25656d6f0a1965794acf07e884844c61876ec1cac5cf303
Contents?: true
Size: 916 Bytes
Versions: 2
Compression:
Stored size: 916 Bytes
Contents
# Allows to check if the value of a specific attribute is a valid MAC address. # # @example Validate that the device MAC address is valid. # class Device << ActiveRecord::Base # attr_accessor :lon # validates :lon, longitude: true # end class LongitudeValidator < ActiveModel::EachValidator # Checks if an attribute value is a valid MAC address. # # @param [Object] record object to validate # @param [String] attribute name of the object attribute to validate # @param [Object] value attribute value def validate_each(record, attribute, value) allow_blank = options[:allow_blank] || false return if allow_blank && value.blank? unless self.class.valid?(value, options) record.errors[attribute] << (options[:message] || I18n.t('errors.messages.longitude')) end end private def self.valid?(longitude, options) longitude >= -180 && longitude <= 180 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
missing_validators-0.8.1 | lib/missing_validators/validators/longitude_validator.rb |
missing_validators-0.8.0 | lib/missing_validators/validators/longitude_validator.rb |