README.md in bra_document_validation-1.0.0 vs README.md in bra_document_validation-1.0.2

- old
+ new

@@ -1,7 +1,9 @@ # BraDocumentValidation +[![Build Status](https://travis-ci.com/bvicenzo/bra_document_validation.svg?branch=master)](https://travis-ci.com/bvicenzo/bra_document_validation) + This gem allows to validate Brazilian documents, CPF and CNPJ, with format and digit verification. ## Installation Add this line to your application's Gemfile: @@ -10,31 +12,47 @@ gem 'bra_document_validation' ``` And then execute: - $ bundle install +```sh +bundle install +``` Or install it yourself as: - $ gem install bra_document_validation +```sh +gem install bra_document_validation +``` ## Usage ```rb validates :document_number, 'bra_document_validation/cpf': true validates :document_number, 'bra_document_validation/cnpj': true +validates :document_number, 'bra_document_validation/cpf_or_cnpj': true ``` +You might need add CPF and CNPJ acronyms to inflactions. + +```rb +# config/initializers/inflections.rb +ActiveSupport::Inflector.inflections do |inflect| + inflect.acronym 'CPF' + inflect.acronym 'CNPJ' +end +``` + # Format By default, it expects a raw document number (only numbers). However you can pass options if your number is formatted. ```rb validates :document_number, 'bra_document_validation/cpf': { formatted: true } validates :document_number, 'bra_document_validation/cnpj': { formatted: false } +validates :document_number, 'bra_document_validation/cpf_or_cnpj': { formatted: false } ``` # Messaging When the document format does not match `invalid_format` message is added to the errors on field. @@ -42,9 +60,10 @@ However you can add a custom message that substitute the above messages. ```rb validates :document_number, 'bra_document_validation/cpf': { message: :invalid } validates :document_number, 'bra_document_validation/cnpj': { message: 'A custom message' } +validates :document_number, 'bra_document_validation/cpf_or_cnpj': { message: :invalid } ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.