Class: RegexForms::ValidateCNPJ
- Inherits:
-
Object
- Object
- RegexForms::ValidateCNPJ
- Defined in:
- lib/regex_forms.rb
Instance Attribute Summary collapse
-
#cnpj ⇒ Object
readonly
Returns the value of attribute cnpj.
Instance Method Summary collapse
-
#initialize(cnpj) ⇒ ValidateCNPJ
constructor
A new instance of ValidateCNPJ.
- #validate ⇒ Object
Constructor Details
#initialize(cnpj) ⇒ ValidateCNPJ
Returns a new instance of ValidateCNPJ.
39 40 41 |
# File 'lib/regex_forms.rb', line 39 def initialize(cnpj) @cnpj = cnpj end |
Instance Attribute Details
#cnpj ⇒ Object (readonly)
Returns the value of attribute cnpj.
37 38 39 |
# File 'lib/regex_forms.rb', line 37 def cnpj @cnpj end |
Instance Method Details
#validate ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/regex_forms.rb', line 43 def validate return invalid_response("CNPJ is nil, empty, or all zeros") if invalid_cnpj? regex = /^(?<t_1>\d{2})\.(?<t_2>\d{3})\.(?<t_3>\d{3})\/0001-(?<t_4>\d{2})$/ if regex.match(cnpj) valid_response("Validated CNPJ") else invalid_response("Invalid CNPJ: #{cnpj}") end end |