Module: Faker::PhoneNumberSE

Extended by:
ModuleUtils, PhoneNumberSE
Included in:
PhoneNumberSE
Defined in:
lib/ffakerer/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 =
k ["%s-### ### ##",
"%s-### ## ##",
"%s-## ## ##"]
PHONE_FORMAT_PREFIX_3 =
k ["%s-### ## ##",
"%s-## ## ##",
"%s-## ###"]
PHONE_FORMAT_PREFIX_4 =
k ["%s-## ## ##",
"%s-### ##"]
MOBILE_PHONE_FORMAT =
k ["%s#-## ## ##", "%s#-######"]
COUNTRY_PREFIX =
k ["+46", "0046"]
MOBILE_PHONE_PREFIX =
k %w(70 72 73 76 74)

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore

Instance Method Details

#area_prefixObject



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

def area_prefix
  PHONE_PREFIX.rand
end

#country_prefixObject



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

def country_prefix
  COUNTRY_PREFIX.rand
end

#home_work_phone_numberObject



29
30
31
# File 'lib/ffakerer/phone_number_se.rb', line 29

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

#international_home_work_phone_numberObject



52
53
54
# File 'lib/ffakerer/phone_number_se.rb', line 52

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

#international_mobile_phone_numberObject



48
49
50
# File 'lib/ffakerer/phone_number_se.rb', line 48

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

#international_phone_numberObject



37
38
39
40
41
42
# File 'lib/ffakerer/phone_number_se.rb', line 37

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



33
34
35
# File 'lib/ffakerer/phone_number_se.rb', line 33

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

#mobile_phone_number_formatObject



73
74
75
# File 'lib/ffakerer/phone_number_se.rb', line 73

def mobile_phone_number_format
  MOBILE_PHONE_FORMAT.rand % mobile_prefix
end

#mobile_prefixObject



69
70
71
# File 'lib/ffakerer/phone_number_se.rb', line 69

def mobile_prefix
  MOBILE_PHONE_PREFIX.rand
end

#phone_numberObject



22
23
24
25
26
27
# File 'lib/ffakerer/phone_number_se.rb', line 22

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

#phone_number_formatObject



60
61
62
63
64
65
66
67
# File 'lib/ffakerer/phone_number_se.rb', line 60

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