Module: FFaker::PhoneNumberSE

Extended by:
ModuleUtils, PhoneNumberSE
Included in:
PhoneNumberSE
Defined in:
lib/ffaker/phone_number_se.rb

Overview

Format for swedish numbers, from here from sv.wikipedia.org/wiki/Telefonnummer

All area codes are from this list sv.wikipedia.org/wiki/Lista_%C3%B6ver_svenska_riktnummer

  • Length 9 08-xxx xxx xx, 0xx-xxx xx xx, 0xxx-xx xx xx

  • Length 8 08-xxx xx xx, 0xx-xx xx xx, 0xxx-xxx xx

  • Length 7 08-xx xx xx, 0xx-xxx xx

Constant Summary collapse

PHONE_FORMAT_PREFIX_2 =
['%s-### ### ##',
'%s-### ## ##',
'%s-## ## ##'].freeze
PHONE_FORMAT_PREFIX_3 =
['%s-### ## ##',
'%s-## ## ##',
'%s-## ###'].freeze
PHONE_FORMAT_PREFIX_4 =
['%s-## ## ##',
'%s-### ##'].freeze
MOBILE_PHONE_FORMAT =
['%s#-## ## ##', '%s#-######'].freeze
COUNTRY_PREFIX =
['+46', '0046'].freeze
MOBILE_PHONE_PREFIX =
%w[70 72 73 76 74].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

#area_prefixObject



67
68
69
# File 'lib/ffaker/phone_number_se.rb', line 67

def area_prefix
  fetch_sample(PHONE_PREFIX)
end

#country_prefixObject



55
56
57
# File 'lib/ffaker/phone_number_se.rb', line 55

def country_prefix
  fetch_sample(COUNTRY_PREFIX)
end

#home_work_phone_numberObject



40
41
42
# File 'lib/ffaker/phone_number_se.rb', line 40

def home_work_phone_number
  FFaker.numerify("0#{phone_number_format}")
end

#international_home_work_phone_numberObject



63
64
65
# File 'lib/ffaker/phone_number_se.rb', line 63

def international_home_work_phone_number
  FFaker.numerify("#{country_prefix} (0)#{phone_number_format}")
end

#international_mobile_phone_numberObject



59
60
61
# File 'lib/ffaker/phone_number_se.rb', line 59

def international_mobile_phone_number
  FFaker.numerify("#{country_prefix} (0)#{mobile_phone_number_format}")
end

#international_phone_numberObject



48
49
50
51
52
53
# File 'lib/ffaker/phone_number_se.rb', line 48

def international_phone_number
  case rand(0..1)
  when 0 then international_mobile_phone_number
  when 1 then international_home_work_phone_number
  end
end

#mobile_phone_numberObject



44
45
46
# File 'lib/ffaker/phone_number_se.rb', line 44

def mobile_phone_number
  FFaker.numerify("0#{mobile_phone_number_format}")
end

#mobile_phone_number_formatObject



84
85
86
# File 'lib/ffaker/phone_number_se.rb', line 84

def mobile_phone_number_format
  fetch_sample(MOBILE_PHONE_FORMAT) % mobile_prefix
end

#mobile_prefixObject



80
81
82
# File 'lib/ffaker/phone_number_se.rb', line 80

def mobile_prefix
  fetch_sample(MOBILE_PHONE_PREFIX)
end

#phone_numberObject



33
34
35
36
37
38
# File 'lib/ffaker/phone_number_se.rb', line 33

def phone_number
  case rand(0..1)
  when 0 then home_work_phone_number
  when 1 then mobile_phone_number
  end
end

#phone_number_formatObject



71
72
73
74
75
76
77
78
# File 'lib/ffaker/phone_number_se.rb', line 71

def phone_number_format
  prefix = area_prefix
  case prefix.length
  when 1 then fetch_sample(PHONE_FORMAT_PREFIX_2)
  when 2 then fetch_sample(PHONE_FORMAT_PREFIX_3)
  when 3 then fetch_sample(PHONE_FORMAT_PREFIX_4)
  end % prefix
end