Sha256: 3c382524c5a3b911f635cfc5e97ef5ab419c3bd48731a1ed01c7e1b9d1b61f89
Contents?: true
Size: 369 Bytes
Versions: 2
Compression:
Stored size: 369 Bytes
Contents
# frozen_string_literal: true class CNPJ class Formatter STRICT_REGEX = %r[[/.-]] LOOSE_REGEX = /[^\d]/ 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 def self.strip(number, strict = false) number.to_s.gsub(strict ? STRICT_REGEX : LOOSE_REGEX, "") end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cpf_cnpj-0.5.0 | lib/cnpj/formatter.rb |
cpf_cnpj-0.4.1 | lib/cnpj/formatter.rb |