class Faker::ChileRut

def check_digit

Returns:
  • (String) -
def check_digit
  dv
end

def dv

Returns:
  • (String) -
def dv
  split_reversed_rut = @last_rut.to_s.reverse.chars
  seq = [2, 3, 4, 5, 6, 7]
  i = 0
  digit_sum = split_reversed_rut.reduce(0) do |sum, n|
    partial_result = sum.to_i + (n.to_i * seq[i])
    i = i == 5 ? 0 : i + 1
    partial_result
  end
  partial_check_digit = 11 - (digit_sum % 11)
  case partial_check_digit
  when 11
    '0'
  when 10
    'k'
  else
    partial_check_digit.to_s
  end
end

def format_rut(rut)

def format_rut(rut)
  rut.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse
end

def full_rut(min_rut: 1, max_rut: 99_999_999, fixed: false, formatted: false)

Returns:
  • (String) -

Parameters:
  • fixed (Boolean) -- Determines if the RUT is fixed (returns the min_rut value).
  • max_rut (Integer) -- Specifies the maximum value of the RUT.
  • min_rut (Integer) -- Specifies the minimum value of the RUT.
def full_rut(min_rut: 1, max_rut: 99_999_999, fixed: false, formatted: false)
  this_rut = rut(min_rut: min_rut, max_rut: max_rut, fixed: fixed)
  this_rut = format_rut(this_rut) if formatted
  "#{this_rut}-#{dv}"
end

def rut(min_rut: 1, max_rut: 99_999_999, fixed: false)

Returns:
  • (Number) -

Parameters:
  • fixed (Boolean) -- Determines if the RUT is fixed (returns the min_rut value).
  • max_rut (Integer) -- Specifies the maximum value of the RUT.
  • min_rut (Integer) -- Specifies the minimum value of the RUT.
def rut(min_rut: 1, max_rut: 99_999_999, fixed: false)
  @last_rut = fixed ? min_rut : rand_in_range(min_rut, max_rut)
end