Skip to content

Commit

Permalink
full_formatted_rut merged into full_rut with param formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlHeitmann committed Aug 18, 2022
1 parent a10d535 commit 9db24fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 34 deletions.
10 changes: 2 additions & 8 deletions doc/default/chile_rut.md
Expand Up @@ -24,13 +24,7 @@ Faker::ChileRut.check_digit #=> "5"
# Keyword arguments: min_rut
# Keyword arguments: fixed
Faker::ChileRut.full_rut #=> "30686957-4"
Faker::ChileRut.full_rut(min_rut: 20890156) #=> "30686957-4"
Faker::ChileRut.full_rut(min_rut: 20890156) #=> "20890156-4"
Faker::ChileRut.full_rut(min_rut: 20890156, formatted: true) #=> "20.890.156-4"
Faker::ChileRut.full_rut(min_rut: 30686957, fixed: true) #=> "30686957-4"

# Returns full formatted rut
# Keyword arguments: min_rut
# Keyword arguments: fixed
Faker::ChileRut.full_formatted_rut #=> "30.686.957-4"
Faker::ChileRut.full_formatted_rut(min_rut: 20890156) #=> "30.686.957-4"
Faker::ChileRut.full_formatted_rut(min_rut: 30686957, fixed: true) #=> "30.686.957-4"
```
29 changes: 5 additions & 24 deletions lib/faker/default/chile_rut.rb
Expand Up @@ -83,36 +83,17 @@ def check_digit
# Faker::ChileRut.full_rut(min_rut: 30686957, fixed: true) #=> "30686957-4"
#
# @faker.version 1.9.2
def full_rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 0, fixed: false)
def full_rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 0, fixed: false, formatted: false)
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)}-#{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)
warn_for_deprecated_arguments do |keywords|
keywords << :min_rut if legacy_min_rut != NOT_GIVEN
keywords << :fixed if legacy_fixed != NOT_GIVEN
if formatted
"#{rut(min_rut: min_rut, fixed: fixed).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse}-#{dv}"
else
"#{rut(min_rut: min_rut, fixed: fixed)}-#{dv}"
end

"#{rut(min_rut: min_rut, fixed: fixed).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse}-#{dv}"
end

attr_reader :last_rut
Expand Down
4 changes: 2 additions & 2 deletions test/faker/default/test_faker_chile_rut.rb
Expand Up @@ -25,8 +25,8 @@ def test_check_digit
assert @tester.dv == '4'
end

def test_full_formatted_rut_has_dv
assert @tester.full_formatted_rut(min_rut: 30_686_957, fixed: true).split('-')[0] == '30.686.957'
def test_full_formatted_rut
assert @tester.full_rut(min_rut: 30_686_957, fixed: true, formatted: true).split('-')[0] == '30.686.957'
assert @tester.dv == '4'
end
end

0 comments on commit 9db24fb

Please sign in to comment.