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 ChileRut.full_formatted_rut #2460
Changes from 5 commits
3c22cc2
dd851a2
2bfb3e0
2e18995
a10d535
9db24fb
c62c5b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,29 @@ def full_rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 0, f | |
"#{rut(min_rut: min_rut, fixed: fixed)}-#{dv}" | ||
end | ||
|
||
## | ||
# Produces a random Chilean RUT (Rol Unico Tributario, ID with 8 digits) with a dv (digito verificador, check-digit). | ||
# with character passed in argument as separator. | ||
# | ||
# @param min_rut [Integer] Specifies the minimum value of the rut. | ||
# @param fixed [Boolean] Determines if the rut is fixed (returns the min_rut value). | ||
# @return [String] | ||
# | ||
# @example | ||
# Faker::ChileRut.full_rut_with_dots #=> "30.686.957-4" | ||
# Faker::ChileRut.full_rut_with_dots(min_rut: 20890156) #=> "30.686.957-4" | ||
# Faker::ChileRut.full_rut_with_dots(min_rut: 30686957, fixed: true) #=> "30.686.957-4" | ||
# | ||
# @faker.version next | ||
def full_formatted_rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 0, fixed: false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this is a new geneator, there souldn't be any legacy params to pass in. These can just be keyword params, and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot to ask that on my review, thanks for the comment @Zeragamba! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi! I don't quite understand, is this related with your first commit here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's confusing because the other methods handle this legacy/deprecation stuff :/ It's going to be removed soon. What @Zeragamba means is that for new methods, you don't need the legacy params and the arn_for_deprecated_arguments` block. See this previous PR merging a similar feature without the legacy/deprecation checks. |
||
warn_for_deprecated_arguments do |keywords| | ||
keywords << :min_rut if legacy_min_rut != NOT_GIVEN | ||
keywords << :fixed if legacy_fixed != NOT_GIVEN | ||
end | ||
|
||
"#{rut(min_rut: min_rut, fixed: fixed).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse}-#{dv}" | ||
end | ||
|
||
attr_reader :last_rut | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,9 @@ def test_check_digit | |
assert @tester.rut(min_rut: 30_686_957, fixed: true) == 30_686_957 | ||
assert @tester.dv == '4' | ||
end | ||
|
||
def test_full_formatted_rut_has_dv | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DV stands for "digito verificador", "verifying digit" will be the translation, I guess. DV is some kind of checksum of chilean citizen number (rut). There is a mathematical formula described here, you take the citizen number before hyphen as input, and the result is a number between 1-11. If the output is 10, DV = K, if the output is 11, DV = 0. This feature is implemented in the method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks! The confusing part was having |
||
assert @tester.full_formatted_rut(min_rut: 30_686_957, fixed: true).split('-')[0] == '30.686.957' | ||
assert @tester.dv == '4' | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of following the same pattern we use when generating ID Numbers? i.e.:
That way we could simply have a
formatted:
keyword in the keywordfull_rut
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is the pattern and the rule I will follow it. Please confirm and I can merge this method with the existing one
full_rut
, using theformatted:
argument to switch from full rut or full_formatted_rut. I can follow the brazilian citizen number as an example. I believe I'll have to rewrite the tests, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go with the pattern to keep things tidy. About the tests: yes, you'll have to update it. I would follow the Brazilian ID scenarios as seen here.
In this case, we would need cases for testing:
fixed
true and false cases