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 YARD docs to Faker::Chile_Rut #2054

Merged
merged 2 commits into from
Jun 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion lib/faker/default/chile_rut.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ class ChileRut < Base
class << self
@last_rut = nil

# Fixed param added for testing a specific RUT and check digit combination.
##
# Produces a random Chilean RUT (Rol Unico Tributario, ID with 8 digits).
#
# @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 [Number]
#
# @example
# Faker::ChileRut.rut #=> 11235813
# Faker::ChileRut.rut(min_rut: 20890156) #=> 31853211
# Faker::ChileRut.rut(min_rut: 20890156, fixed: true) #=> 20890156
#
# @faker.version 1.9.2
def rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 1, fixed: false)
warn_for_deprecated_arguments do |keywords|
keywords << :min_rut if legacy_min_rut != NOT_GIVEN
Expand All @@ -15,6 +27,15 @@ def rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 1, fixed:
@last_rut = fixed ? min_rut : rand_in_range(min_rut, 99_999_999)
end

##
# Produces a random Chilean digito verificador (check-digit).
#
# @return [String]
#
# @example
# Faker::ChileRut.dv #=> "k"
#
# @faker.version 1.9.2
def dv
split_reversed_rut = @last_rut.to_s.reverse.split('')
seq = [2, 3, 4, 5, 6, 7]
Expand All @@ -34,11 +55,33 @@ def dv
end
end

##
# Produces a random Chilean digito verificador (check-digit).
# Alias for english speaking devs.
#
# @return [String]
#
# @example
# Faker::ChileRut.check_digit #=> "5"
#
# @faker.version 1.9.2
def check_digit
dv
end

##
# Produces a random Chilean RUT (Rol Unico Tributario, ID with 8 digits) with a dv (digito verificador, check-digit).
#
# @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 #=> "30686957-4"
# 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
def full_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
Expand Down