Class: CPF::Formatter
- Inherits:
-
Object
- Object
- CPF::Formatter
- Defined in:
- lib/cpf/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/cpf/formatter.rb', line 6 def self.format(number) strip(number).gsub(/\A(\d{3})(\d{3})(\d{3})(\d{2})\Z/, "\\1.\\2.\\3-\\4") end |
.strip(number, strict = false) ⇒ Object
10 11 12 |
# File 'lib/cpf/formatter.rb', line 10 def self.strip(number, strict = false) number.to_s.gsub(strict ? STRICT_REGEX : LOOSE_REGEX, "") end |