Module: Faker::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-## ## ##"]
PHONE_FORMAT_PREFIX_3 =
["%s-### ## ##",
"%s-## ## ##",
"%s-## ###"]
PHONE_FORMAT_PREFIX_4 =
["%s-## ## ##",
"%s-### ##"]
MOBILE_PHONE_FORMAT =
["%s#-## ## ##", "%s#-######"]
COUNTRY_PREFIX =
["+46", "0046"]
MOBILE_PHONE_PREFIX =
%w(70 72 73 76 74)

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore

Instance Method Details

#area_prefixObject



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

def area_prefix
  PHONE_PREFIX.sample
end

#country_prefixObject



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

def country_prefix
  COUNTRY_PREFIX.sample
end

#home_work_phone_numberObject



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

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

#international_home_work_phone_numberObject



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

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

#international_mobile_phone_numberObject



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

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

#international_phone_numberObject



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

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

#mobile_phone_numberObject



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

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

#mobile_phone_number_formatObject



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

def mobile_phone_number_format
  MOBILE_PHONE_FORMAT.sample % mobile_prefix
end

#mobile_prefixObject



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

def mobile_prefix
  MOBILE_PHONE_PREFIX.sample
end

#phone_numberObject



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

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

#phone_number_formatObject



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

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