Class: Faker::ChileRut
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Attribute Summary collapse
-
.last_rut ⇒ Object
readonly
Returns the value of attribute last_rut.
Class Method Summary collapse
-
.check_digit ⇒ String
Produces a random Chilean digito verificador (check-digit).
-
.dv ⇒ String
Produces a random Chilean digito verificador (check-digit).
-
.full_rut(min_rut: 1, max_rut: 99_999_999, fixed: false, formatted: false) ⇒ String
Produces a random Chilean RUT (Rol Unico Tributario, ID with 8 digits) with a dv (digito verificador, check-digit).
-
.rut(min_rut: 1, max_rut: 99_999_999, fixed: false) ⇒ Number
Produces a random Chilean RUT (Rol Unico Tributario, ID with 8 digits).
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale
Class Attribute Details
.last_rut ⇒ Object (readonly)
Returns the value of attribute last_rut.
89 90 91 |
# File 'lib/faker/default/chile_rut.rb', line 89 def last_rut @last_rut end |
Class Method Details
.check_digit ⇒ String
Produces a random Chilean digito verificador (check-digit). Alias for english speaking devs.
65 66 67 |
# File 'lib/faker/default/chile_rut.rb', line 65 def check_digit dv end |
.dv ⇒ String
Produces a random Chilean digito verificador (check-digit).
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/faker/default/chile_rut.rb', line 35 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 |
.full_rut(min_rut: 1, max_rut: 99_999_999, fixed: false, formatted: false) ⇒ String
Produces a random Chilean RUT (Rol Unico Tributario, ID with 8 digits) with a dv (digito verificador, check-digit).
83 84 85 86 87 |
# File 'lib/faker/default/chile_rut.rb', line 83 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 |
.rut(min_rut: 1, max_rut: 99_999_999, fixed: false) ⇒ Number
Produces a random Chilean RUT (Rol Unico Tributario, ID with 8 digits).
22 23 24 |
# File 'lib/faker/default/chile_rut.rb', line 22 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 |