Class: ActiveModel::Validations::IbanValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/active_model/validations/iban_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/active_model/validations/iban_validator.rb', line 11

def validate_each(record, attribute, value)
  return unless value.present?

  if !IbanBic.parse(value)
    record.errors.add(attribute, :invalid_format)
  elsif !IbanBic.valid_check?(value)
    record.errors.add(attribute, :invalid_check)
  elsif !IbanBic.valid_country_check?(value)
    record.errors.add(attribute, :invalid_country_check)
  elsif options[:tags] && !IbanBic.has_tags?(value, options[:tags])
    record.errors.add(attribute, :invalid_tag)
  end
end