class MacAddressValidator

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/active_validation/validators/mac_address_validator.rb, line 14
def validate_each(record, attribute, value)
  return if valid?(value.to_s)

  record.errors[attribute] <<
    (options[:message] || I18n.t('active_validation.errors.messages.mac_address'))
end

Private Instance Methods

valid?(value) click to toggle source
# File lib/active_validation/validators/mac_address_validator.rb, line 36
def valid?(value)
  valid_length?(value) &&
    valid_format?(value)
end
valid_format?(value) click to toggle source
# File lib/active_validation/validators/mac_address_validator.rb, line 23
def valid_format?(value)
  result = false
  DEFAULT_FORMATS.each do |pat|
    result = (value =~ pat)
    break if result
  end
  result
end
valid_length?(value) click to toggle source
# File lib/active_validation/validators/mac_address_validator.rb, line 32
def valid_length?(value)
  value.present?
end