Sha256: 28b4520a8e1eb176e51e7ca8b47864a67b3b84baf8ebcffa1e6ecd5234446b7d

Contents?: true

Size: 758 Bytes

Versions: 3

Compression:

Stored size: 758 Bytes

Contents

# encoding: utf-8

require 'ffaker/identification_es'

module FFaker
  module IdentificationESCL
    extend IdentificationES
    extend self

    # RUT is the Chilean ID, followed by format:  XX.XXX.XXX - Y
    # http://es.wikipedia.org/wiki/Rol_%C3%9Anico_Tributario
    #
    # The last Y is a modulo 11 validation code. In the case the result is 10, it will be replaced by a 'K' character
    def rut
      # Rut is gonna be between 1.000.000 and 24.999.999
      n = Kernel.rand(24000000) + 1000000
      "#{n}-#{dv(n)}"
    end

    private
      def dv(rut)
        total = rut.to_s.rjust(8,'0').split(//).zip(%w(3 2 7 6 5 4 3 2)).collect{|a,b| a.to_i*b.to_i}.inject(:+)
        (11 - total % 11).to_s.gsub(/10/,'k').gsub(/11/,'0')
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffaker-2.2.0 lib/ffaker/identification_es_cl.rb
ffaker-2.1.0 lib/ffaker/identification_es_cl.rb
ffaker-2.0.0 lib/ffaker/identification_es_cl.rb