Module: Faker::SSNSE

Extended by:
ModuleUtils, SSNSE
Included in:
SSNSE
Defined in:
lib/ffakerer/ssn_se.rb

Overview

The Social Security number is a 12-digit number in the format: “YYYYDDMM-XXXX’

sv.wikipedia.org/wiki/Personnummer_i_Sverige

The 4 last digits (XXXX) are generated based on what region the person are born # in, the gender and the last one is a check digit using the luhn algorithm.

en.wikipedia.org/wiki/Luhn_algorithm

Usage: ssn(from: Time.local(1980, 2, 28),

to: Time.local(2000, 2, 28),
gender: :male)

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore

Instance Method Details

#ssn(opts = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/ffakerer/ssn_se.rb', line 27

def ssn(opts = {})
  from   = opts[:from]   || ::Time.local(1940, 1, 1)
  to     = opts[:to]     || ::Time.now
  gender = (opts[:gender] || GENDERS.rand).to_s

  raise_error_on_bad_arguments(from, to, gender)

  generate_ssn(from, to, gender)
end