Skip to content

Implement package cnpj-fmt #3

@juliolmuller

Description

@juliolmuller

Overview

Implement the cnpj-fmt Ruby gem — a class-based utility for formatting and parsing CNPJ strings, fully compatible with both the traditional numeric and the upcoming alphanumeric CNPJ formats.

Background

The current CNPJ structure is purely numerical, following the format 99.999.999/9999-99 with check digits for validation. Brazil's Tax Reform introduces an alphanumeric CNPJ format, replacing the purely numeric model while keeping the same 14-character length. Under the new format, the first 12 characters of the CNPJ include letters and numbers; the last two characters remain numeric check digits. This update is effective from July 2026, and existing CNPJs containing numeric characters only will continue to be valid and recognized.

Goals

  • Implement a class-based interface within the CnpjFmt module that exposes methods to format and parse CNPJ strings.
  • Apply the standard CNPJ mask: XX.XXX.XXX/XXXX-XX.
  • Strip the mask from a formatted CNPJ, returning only the raw alphanumeric characters.
  • Accept both numeric-only (legacy) and alphanumeric (new format) CNPJs as valid inputs.
  • Follow the same conventions already adopted by sibling packages in this monorepo (e.g. cpf-fmt).

Expected API (tentative)

# Apply mask
CnpjFmt.format('11222333000181')   # => '11.222.333/0001-81'
CnpjFmt.format('11ABC3330001DE')   # => '11.ABC.333/0001-DE'

# Strip mask
CnpjFmt.unformat('11.222.333/0001-81')  # => '11222333000181'
CnpjFmt.unformat('11.ABC.333/0001-DE')  # => '11ABC3330001DE'

Acceptance Criteria

  • CnpjFmt.format(cnpj) returns the CNPJ string with the XX.XXX.XXX/XXXX-XX mask applied.
  • CnpjFmt.unformat(cnpj) returns the raw CNPJ string with all punctuation removed.
  • Both methods handle numeric-only and alphanumeric CNPJs (uppercase letters A–Z).
  • Unit tests cover formatting and unformatting for both CNPJ variants (numeric and alphanumeric).
  • The gem version is set to 0.1.0 upon first functional release.
  • The gemspec summary and description are updated to reflect the actual functionality.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew minor or major features.

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions