Class: Brid::CPF
Instance Attribute Summary
Attributes inherited from GenericID
Instance Method Summary collapse
- #check_digits_length ⇒ Object
- #from?(uf) ⇒ Boolean
- #inspect ⇒ Object
- #number_length ⇒ Object
- #origin ⇒ Object
- #to_s ⇒ Object
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_length ⇒ Object
4 |
# File 'lib/brid/ids/cpf.rb', line 4 def check_digits_length; 2; end |
#from?(uf) ⇒ Boolean
31 32 33 |
# File 'lib/brid/ids/cpf.rb', line 31 def from? uf origin.include? uf end |
#inspect ⇒ Object
10 11 12 |
# File 'lib/brid/ids/cpf.rb', line 10 def inspect "#<CPF: #{to_s} #{valid? ? 'valid': 'not valid'} >" end |
#number_length ⇒ Object
3 |
# File 'lib/brid/ids/cpf.rb', line 3 def number_length; 11; end |
#origin ⇒ Object
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_s ⇒ Object
6 7 8 |
# File 'lib/brid/ids/cpf.rb', line 6 def to_s "#{sequential.scan(/\d{3}/).join('.')}-#{check_digits}" end |