class Faker::ChileRut

Attributes

last_rut[R]

Public Class Methods

check_digit() click to toggle source

Alias for english speaking devs.

# File lib/faker/default/chile_rut.rb, line 38
def check_digit
  dv
end
dv() click to toggle source
# File lib/faker/default/chile_rut.rb, line 18
def dv
  split_reversed_rut = @last_rut.to_s.reverse.split('')
  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)
  if partial_check_digit == 11
    '0'
  elsif partial_check_digit == 10
    'k'
  else
    partial_check_digit.to_s
  end
end
full_rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 0, fixed: false) click to toggle source
# File lib/faker/default/chile_rut.rb, line 42
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
    keywords << :fixed if legacy_fixed != NOT_GIVEN
  end

  "#{rut(min_rut: min_rut, fixed: fixed)}-#{dv}"
end
rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 1, fixed: false) click to toggle source

Fixed param added for testing a specific RUT and check digit combination.

# File lib/faker/default/chile_rut.rb, line 9
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
    keywords << :fixed if legacy_fixed != NOT_GIVEN
  end

  @last_rut = fixed ? min_rut : rand_in_range(min_rut, 99_999_999)
end