Sha256: 64555eeb993c41cad1651c302c8f65fb82374ad756cb8f73797ac61d75b20780
Contents?: true
Size: 354 Bytes
Versions: 2
Compression:
Stored size: 354 Bytes
Contents
# frozen_string_literal: true class CPF class Formatter STRICT_REGEX = /[.-]/ LOOSE_REGEX = /[^\d]/ def self.format(number) strip(number).gsub(/\A(\d{3})(\d{3})(\d{3})(\d{2})\Z/, "\\1.\\2.\\3-\\4") 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/cpf/formatter.rb |
cpf_cnpj-0.4.1 | lib/cpf/formatter.rb |