Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to formatted brazilian_citizen_number and brazilian_company_number #1489

Merged
merged 1 commit into from
Dec 7, 2018

Conversation

franciscomxs
Copy link
Contributor

Add support to valid and full random brazilian documents: CPF (person id) and CNPJ (company id).

@franciscomxs franciscomxs force-pushed the feat/brazilian-cpf-and-cnpj branch 3 times, most recently from eef1195 to 2f4a877 Compare December 4, 2018 23:29
@franciscomxs
Copy link
Contributor Author

franciscomxs commented Dec 4, 2018

There is a offense in rubocop that says "Favor format over String#%" and forces me to change this:

'%s.%s.%s-%s' % number.scan(/\d{2,3}/).flatten

to this:

named_captures = number.match(/(?<a>\d{3})(?<b>\d{3})(?<c>\d{3})(?<d>\d{2})/).named_captures
named_captures = named_captures.each.with_object({}) { |(k, v), hash| hash[k.to_sym] = v }
@formatted ||= format('%<a>s.%<b>s.%<c>s-%<d>s', named_captures)

Is it ok to ignore this offense in .rubocop.yml?

I will improve this PR until tomorrow.

@stympy
Copy link
Contributor

stympy commented Dec 5, 2018

Yes, you can update the rubocop config to ignore that rule.

Copy link
Member

@vbrazo vbrazo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly thanks for following the structure of the unreleased project. We appreciate that!

It seems we already have these faker methods:

I think you could improve them. Please review these methods and let me know what you think.

@vbrazo vbrazo changed the title Feat: brazilian cpf and cnpj Brazilian CPF and CNPJ Dec 5, 2018
@vbrazo vbrazo changed the title Brazilian CPF and CNPJ Add Faker::CNPJ and Faker::CPF Dec 5, 2018
@vbrazo
Copy link
Member

vbrazo commented Dec 5, 2018

Just noticed that currently we don't have an option to output a formatted/unformatted response. This feature request is welcome!

@franciscomxs
Copy link
Contributor Author

Thank you for the info. I will improve the existent method to allow formatted numbers instead of a creating a new one.

@franciscomxs franciscomxs force-pushed the feat/brazilian-cpf-and-cnpj branch from 2f4a877 to 6f5b7fc Compare December 5, 2018 13:38
@franciscomxs franciscomxs changed the title Add Faker::CNPJ and Faker::CPF Add support to formatted Faker::IDNumber.brazilian_citizen_number and Faker::Company.brazilian_company_number Dec 5, 2018
@franciscomxs franciscomxs changed the title Add support to formatted Faker::IDNumber.brazilian_citizen_number and Faker::Company.brazilian_company_number Add support to formatted brazilian_citizen_number and brazilian_company_number Dec 5, 2018
@franciscomxs
Copy link
Contributor Author

@vbrazo what do you think?

@vbrazo vbrazo merged commit 92c1582 into faker-ruby:master Dec 7, 2018
@franciscomxs franciscomxs deleted the feat/brazilian-cpf-and-cnpj branch February 13, 2019 12:52
davidmorton0 pushed a commit to davidmorton0/faker that referenced this pull request Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants