Class: CustomerCnpjValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/customer_cnpj_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/validators/customer_cnpj_validator.rb', line 2

def validate_each(record, attribute, value)
  
  if (record.person_type==CustomerPj.to_s)
    
    #cnpj
    unless (!record.complete? && ((value == "") || (value == '0'*14) || (Cnpj.new(value).valido?))) || 
           (Cnpj.new(value).valido?)
      record.errors[attribute] << (options[:message] || ("%s %s" % [I18n.t("customer_pjs.doc"), I18n.t('errors.messages.invalid')]) )
    end
    
  end
end