All Projects â†’ fnando â†’ Cpf_cnpj

fnando / Cpf_cnpj

Licence: mit
🇧🇷 Validate, generate and format CPF/CNPJ numbers. Include command-line tools.

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Cpf cnpj

Tty Exit
Terminal exit codes.
Stars: ✭ 101 (-40.94%)
Mutual labels:  gem
Rubicure
All about Japanese battle heroine "Pretty Cure (Precure)"
Stars: ✭ 119 (-30.41%)
Mutual labels:  gem
Scallop
Ergonomic shell wrapper for Ruby.
Stars: ✭ 150 (-12.28%)
Mutual labels:  gem
Premailer Rails
CSS styled emails without the hassle.
Stars: ✭ 1,382 (+708.19%)
Mutual labels:  gem
Searchobjectgraphql
GraphQL plugin for SearchObject gem
Stars: ✭ 118 (-30.99%)
Mutual labels:  gem
Net Http2
NetHttp2 is an HTTP/2 client for Ruby.
Stars: ✭ 126 (-26.32%)
Mutual labels:  gem
Instagram api gem
A Ruby wrapper for the Instagram API
Stars: ✭ 100 (-41.52%)
Mutual labels:  gem
Searchobject
Search object DSL
Stars: ✭ 152 (-11.11%)
Mutual labels:  gem
Dry Logic
Predicate logic with rule composition
Stars: ✭ 118 (-30.99%)
Mutual labels:  gem
Wordmove
Multi-stage command line deploy/mirroring and task runner for Wordpress
Stars: ✭ 1,791 (+947.37%)
Mutual labels:  gem
Counter culture
Turbo-charged counter caches for your Rails app.
Stars: ✭ 1,397 (+716.96%)
Mutual labels:  gem
Kovid
A CLI to fetch and compare the 2019 coronavirus pandemic statistics. It also fetches historical data and attempts to draw histograms of it to visualise the rate of infections.
Stars: ✭ 107 (-37.43%)
Mutual labels:  gem
Rails sortable
Easy drag & drop sorting with persisting the arranged order for rails
Stars: ✭ 127 (-25.73%)
Mutual labels:  gem
Graphql devise
GraphQL interface on top devise_token_auth
Stars: ✭ 100 (-41.52%)
Mutual labels:  gem
Bump
Bump is a gem that will simplify the way you build gems.
Stars: ✭ 150 (-12.28%)
Mutual labels:  gem
Warden Github Rails
Use GitHub as authorization and more. Use organizations and teams as means of authorization by simply wrapping your rails routes in a block. Also useful to get a user's details through OAuth.
Stars: ✭ 100 (-41.52%)
Mutual labels:  gem
Foot traffic
Pure Ruby DSL for Chrome scripting based on Ferrum. No Selenium required. Works from any script. Simulate web app usage scenarios in production or locally.
Stars: ✭ 123 (-28.07%)
Mutual labels:  gem
Ordinare
Ordinare sorts gems in your Gemfile alphabetically
Stars: ✭ 153 (-10.53%)
Mutual labels:  gem
Spina
Spina CMS
Stars: ✭ 1,926 (+1026.32%)
Mutual labels:  gem
Unityraytracinggem
💎 Ray tracing gem shader for Unity
Stars: ✭ 140 (-18.13%)
Mutual labels:  gem

CPF/CNPJ

Build Status Code Climate Gem Version

This gem does some CPF/CNPJ magic. It allows you to create, validate and format CPF/CNPJ, even through the command-line.

Just making my life easier when filling these damn numbers on internet bankings and government sites.

For ActiveModel/ActiveRecord validations, please check https://github.com/fnando/validators.

Installation

Add this line to your application's Gemfile:

gem "cpf_cnpj"

And then execute:

$ bundle

Or install it yourself as:

$ gem install cpf_cnpj

Usage

Ruby API

This library has the same API for both CNPJ/CPF, so only one of them is documented below.

require "cpf_cnpj"

CPF.valid?(number)    # Check if a CPF is valid
CPF.generate          # Generate a random CPF number
CPF.generate(true)    # Generate a formatted number

cpf = CPF.new(number)
cpf.formatted         # Return formatted CPF (xxx.xxx.xxx-xx)
cpf.stripped          # Return stripped CPF (xxxxxxxxxxx)
cpf.valid?            # Check if CPF is valid

Strict Validation

By default, validations will strip any characters that aren't numbers. This means that 532#####820------857\n96 is considered a valid number. To perform a strict validation use strict: true.

CPF.valid?(number, strict: true)

Command-line

This library gives you two binaries: cpf and cnpj.

$ cpf --check 532.820.857-96
$ $?
0

$ cpf --check 53282085796
$ $?
0

$ cpf --format 53282085796
532.820.857-96

$ cpf --strip 532.820.857-96
53282085796

$ cpf --generate
417.524.931-17

$ cpf --generate --strip
76001454809

$ echo 76001454809 | cpf -f
760.014.548-09

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am "Added some feature")
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].