Sha256: 057472686ef551f63ab6e80b14c3b68e5bcb447c905e1b92ab58ceb508a94f12

Contents?: true

Size: 475 Bytes

Versions: 2

Compression:

Stored size: 475 Bytes

Contents

module Brid
  class CNPJ < GenericID
    def number_length; 14; end
    def check_digits_length; 2; end;

    def to_s
      er = /^(.{2})(.{3})(.{3})(.{4})(.{2})/
      "#{@number.gsub(er, '\1.\2.\3/\4-\5')}"
    end

    def inspect
      "#<CNPJ: #{to_s} #{valid? ? 'valid': 'not valid'} >"
    end

    private
    def valid_number
      sequential.mod11(check_digits_length, :base => 2..9)
    end
  end
end

CNPJ = Brid::CNPJ if not defined? CNPJ and not defined? Cnpj

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
brid-0.2.1 lib/brid/ids/cnpj.rb
brid-0.2.0 lib/brid/ids/cnpj.rb