Class: CNPJ::Formatter
- Inherits:
-
Object
- Object
- CNPJ::Formatter
- Defined in:
- lib/cnpj/formatter.rb
Constant Summary collapse
- STRICT_REGEX =
/[\/.-]/
- LOOSE_REGEX =
/[^\d]/
Class Method Summary collapse
Class Method Details
.format(number) ⇒ Object
6 7 8 |
# File 'lib/cnpj/formatter.rb', line 6 def self.format(number) strip(number).gsub(/\A(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})\Z/, "\\1.\\2.\\3/\\4-\\5") end |
.strip(number, strict = false) ⇒ Object
10 11 12 |
# File 'lib/cnpj/formatter.rb', line 10 def self.strip(number, strict = false) number.to_s.gsub(strict ? STRICT_REGEX : LOOSE_REGEX, "") end |