Module: FFaker::SSNSE
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)
Constant Summary collapse
- GENDERS =
%w[female male].freeze
Instance Method Summary collapse
Methods included from ModuleUtils
const_missing, k, luhn_check, underscore, unique
Methods included from RandomUtils
#fetch_sample, #rand, #shuffle
Instance Method Details
#ssn(opts = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/ffaker/ssn_se.rb', line 28 def ssn(opts = {}) from = opts[:from] || ::Time.local(1940, 1, 1) to = opts[:to] || ::Time.now gender = (opts[:gender] || fetch_sample(GENDERS)).to_s raise_error_on_bad_arguments(from, to, gender) generate_ssn(from, to, gender) end |