Class: DocValidator::Rg

Inherits:
Object
  • Object
show all
Defined in:
lib/doc_validator/rg.rb

Class Method Summary collapse

Class Method Details

.format(rg) ⇒ Object



12
13
14
# File 'lib/doc_validator/rg.rb', line 12

def self.format(rg)
  rg.gsub(/(\d{2})(\d{3})(\d{3})(\d{1})/, '\1.\2.\3-\4')
end

.mask(rg) ⇒ Object



16
17
18
19
20
21
# File 'lib/doc_validator/rg.rb', line 16

def self.mask(rg)
  rg = rg.gsub(/\D/, '')
  return rg unless rg.length == 9

  rg.gsub(/(\d{2})(\d{3})(\d{3})(\d{1})/, '***.\2.\3-*')
end

.valid?(rg) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
# File 'lib/doc_validator/rg.rb', line 5

def self.valid?(rg)
  rg = rg.gsub(/\D/, '')
  return false if rg.length != 9

  true
end