Class: Brid::CPF

Inherits:
GenericID show all
Defined in:
lib/brid/ids/cpf.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/cpf.rb', line 4

def check_digits_length; 2; end

#from?(uf) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/brid/ids/cpf.rb', line 31

def from? uf
  origin.include? uf
end

#inspectObject



10
11
12
# File 'lib/brid/ids/cpf.rb', line 10

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

#number_lengthObject



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

def number_length; 11; end

#originObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/brid/ids/cpf.rb', line 14

def origin
  @origin ||= begin
    [
      [:rs],
      [:df, :go, :ms, :mt, :to],
      [:ac, :am, :ap, :pa, :ro, :rr],
      [:ce, :ma, :pi],
      [:al, :pb, :pe, :rn],
      [:ba, :se],
      [:mg],
      [:es, :rj],
      [:sp],
      [:pr, :sc]
    ][sequential[-1,1].to_i]
  end
end

#to_sObject



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

def to_s
  "#{sequential.scan(/\d{3}/).join('.')}-#{check_digits}"
end