Class: DocValidator::Cpf
- Inherits:
-
Object
- Object
- DocValidator::Cpf
- Defined in:
- lib/doc_validator/cpf.rb
Class Method Summary collapse
Class Method Details
.format(cpf) ⇒ Object
12 13 14 |
# File 'lib/doc_validator/cpf.rb', line 12 def self.format(cpf) cpf.gsub(/(\d{3})(\d{3})(\d{3})(\d{2})/, '\1.\2.\3-\4') end |
.mask(cpf) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/doc_validator/cpf.rb', line 16 def self.mask(cpf) cpf = cpf.gsub(/\D/, '') return cpf unless cpf.length == 11 cpf.gsub(/(\d{3})(\d{3})(\d{3})(\d{2})/, '***.\2.\3-**') end |
.valid?(cpf) ⇒ Boolean
5 6 7 8 9 10 |
# File 'lib/doc_validator/cpf.rb', line 5 def self.valid?(cpf) cpf = cpf.gsub(/\D/, '') return false if cpf.length != 11 true end |