From 3c22cc248563c0dcc12804642aaa186428a933ce Mon Sep 17 00:00:00 2001 From: Karl Heitmann Date: Sat, 5 Feb 2022 00:29:07 -0300 Subject: [PATCH 1/7] Add full_rut_with_dots, a method that generates a rut with thousands separated by dots --- lib/faker/default/chile_rut.rb | 23 ++++++++++++++++++++++ test/faker/default/test_faker_chile_rut.rb | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/lib/faker/default/chile_rut.rb b/lib/faker/default/chile_rut.rb index ce0c529ee7..3237535564 100644 --- a/lib/faker/default/chile_rut.rb +++ b/lib/faker/default/chile_rut.rb @@ -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 1.9.2 + def full_rut_with_dots(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 + 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 diff --git a/test/faker/default/test_faker_chile_rut.rb b/test/faker/default/test_faker_chile_rut.rb index e78fc5918e..02f72d658c 100644 --- a/test/faker/default/test_faker_chile_rut.rb +++ b/test/faker/default/test_faker_chile_rut.rb @@ -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_rut_with_dots_has_do + assert @tester.full_rut_with_dots(min_rut: 30_686_957, fixed: true).split('-')[0] == '30.686.957' + assert @tester.dv == '4' + end end From dd851a2b4b5f10e112b9caa5dc74f0ee0e480901 Mon Sep 17 00:00:00 2001 From: Karl Heitmann Date: Sat, 12 Mar 2022 23:36:31 -0300 Subject: [PATCH 2/7] changed Faker::ChileRut.full_rut_with_dots to Faker::ChileRut.full_formatted_rut, a better semantic name --- lib/faker/default/chile_rut.rb | 2 +- test/faker/default/test_faker_chile_rut.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/faker/default/chile_rut.rb b/lib/faker/default/chile_rut.rb index 3237535564..17e40de395 100644 --- a/lib/faker/default/chile_rut.rb +++ b/lib/faker/default/chile_rut.rb @@ -106,7 +106,7 @@ def full_rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 0, f # Faker::ChileRut.full_rut_with_dots(min_rut: 30686957, fixed: true) #=> "30.686.957-4" # # @faker.version 1.9.2 - def full_rut_with_dots(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 0, fixed: false) + 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 diff --git a/test/faker/default/test_faker_chile_rut.rb b/test/faker/default/test_faker_chile_rut.rb index 02f72d658c..98a2f380c3 100644 --- a/test/faker/default/test_faker_chile_rut.rb +++ b/test/faker/default/test_faker_chile_rut.rb @@ -25,8 +25,8 @@ def test_check_digit assert @tester.dv == '4' end - def test_full_rut_with_dots_has_do - assert @tester.full_rut_with_dots(min_rut: 30_686_957, fixed: true).split('-')[0] == '30.686.957' + def test_full_formatted_rut_has_dv + assert @tester.full_formatted_rut(min_rut: 30_686_957, fixed: true).split('-')[0] == '30.686.957' assert @tester.dv == '4' end end From 2bfb3e0893c134f57b19b516e955b1e06ba43bb3 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 6 Aug 2022 12:13:55 -0700 Subject: [PATCH 3/7] add docs for full_rut and full_formatted_rut --- doc/default/chile_rut.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/default/chile_rut.md b/doc/default/chile_rut.md index 0daf64cb9e..473719fccd 100644 --- a/doc/default/chile_rut.md +++ b/doc/default/chile_rut.md @@ -19,4 +19,18 @@ Faker::ChileRut.dv #=> "k" # check_digit is an alias for dv, for English speaking devs Faker::ChileRut.rut #=> 30528772 Faker::ChileRut.check_digit #=> "5" + +# Returns full rut +# Keyword arguments: min_rut +# Keyword arguments: fixed +Faker::ChileRut.full_rut #=> "30.686.957-4" +Faker::ChileRut.full_rut(min_rut: 20890156) #=> "30.686.957-4" +Faker::ChileRut.full_rut(min_rut: 30686957, fixed: true) #=> "30.686.957-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" ``` From 2e18995a45b93e41ce01934751e1bedae8e9a439 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 6 Aug 2022 12:15:13 -0700 Subject: [PATCH 4/7] remote dots --- doc/default/chile_rut.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/default/chile_rut.md b/doc/default/chile_rut.md index 473719fccd..7b3a5bde0c 100644 --- a/doc/default/chile_rut.md +++ b/doc/default/chile_rut.md @@ -23,9 +23,9 @@ Faker::ChileRut.check_digit #=> "5" # Returns full rut # Keyword arguments: min_rut # Keyword arguments: fixed -Faker::ChileRut.full_rut #=> "30.686.957-4" -Faker::ChileRut.full_rut(min_rut: 20890156) #=> "30.686.957-4" -Faker::ChileRut.full_rut(min_rut: 30686957, fixed: true) #=> "30.686.957-4" +Faker::ChileRut.full_rut #=> "30686957-4" +Faker::ChileRut.full_rut(min_rut: 20890156) #=> "30686957-4" +Faker::ChileRut.full_rut(min_rut: 30686957, fixed: true) #=> "30686957-4" # Returns full formatted rut # Keyword arguments: min_rut From a10d5359f1a8b7f9d74dd6ec6e145f212999df34 Mon Sep 17 00:00:00 2001 From: Karl Heitmann Date: Mon, 8 Aug 2022 11:01:21 -0400 Subject: [PATCH 5/7] changed 1.9.2 to next faker.version on chile_rut.rb --- lib/faker/default/chile_rut.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/faker/default/chile_rut.rb b/lib/faker/default/chile_rut.rb index 17e40de395..673c4ecb92 100644 --- a/lib/faker/default/chile_rut.rb +++ b/lib/faker/default/chile_rut.rb @@ -105,7 +105,7 @@ def full_rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 0, f # 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 1.9.2 + # @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 From 9db24fba7d93d360bd8f9f43c43407ed9a0f17a1 Mon Sep 17 00:00:00 2001 From: Karl Heitmann Date: Wed, 17 Aug 2022 20:35:10 -0400 Subject: [PATCH 6/7] full_formatted_rut merged into full_rut with param formatted --- doc/default/chile_rut.md | 10 ++------ lib/faker/default/chile_rut.rb | 29 ++++------------------ test/faker/default/test_faker_chile_rut.rb | 4 +-- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/doc/default/chile_rut.md b/doc/default/chile_rut.md index 7b3a5bde0c..2496131bc2 100644 --- a/doc/default/chile_rut.md +++ b/doc/default/chile_rut.md @@ -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" ``` diff --git a/lib/faker/default/chile_rut.rb b/lib/faker/default/chile_rut.rb index 673c4ecb92..2ce900696c 100644 --- a/lib/faker/default/chile_rut.rb +++ b/lib/faker/default/chile_rut.rb @@ -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 diff --git a/test/faker/default/test_faker_chile_rut.rb b/test/faker/default/test_faker_chile_rut.rb index 98a2f380c3..99d9105748 100644 --- a/test/faker/default/test_faker_chile_rut.rb +++ b/test/faker/default/test_faker_chile_rut.rb @@ -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 From c62c5b72b7e5789a5239e5a06e55b2d0b7ea3fe1 Mon Sep 17 00:00:00 2001 From: Zeragamba Date: Thu, 18 Aug 2022 20:25:41 -0400 Subject: [PATCH 7/7] tag #full_rut with @faker.version next since we're making a change to an existing api, we need to update the version the api is available in. --- lib/faker/default/chile_rut.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/faker/default/chile_rut.rb b/lib/faker/default/chile_rut.rb index 2ce900696c..1ec982c0dc 100644 --- a/lib/faker/default/chile_rut.rb +++ b/lib/faker/default/chile_rut.rb @@ -82,7 +82,7 @@ def check_digit # Faker::ChileRut.full_rut(min_rut: 20890156) #=> "30686957-4" # Faker::ChileRut.full_rut(min_rut: 30686957, fixed: true) #=> "30686957-4" # - # @faker.version 1.9.2 + # @faker.version next 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