Class: Brid::CNPJ

Inherits:
GenericID show all
Defined in:
lib/brid/ids/cnpj.rb

Instance Attribute Summary

Attributes inherited from GenericID

#number

Instance Method Summary collapse

Methods inherited from GenericID

#check_digits, #freeze, #initialize, #invalid_sequential?, #sequential, #valid?

Constructor Details

This class inherits a constructor from GenericID

Instance Method Details

#check_digits_lengthObject



4
# File 'lib/brid/ids/cnpj.rb', line 4

def check_digits_length; 2; end

#inspectObject



11
12
13
# File 'lib/brid/ids/cnpj.rb', line 11

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

#number_lengthObject



3
# File 'lib/brid/ids/cnpj.rb', line 3

def number_length; 14; end

#to_sObject



6
7
8
9
# File 'lib/brid/ids/cnpj.rb', line 6

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