Module: FFaker::PhoneNumberCU

Extended by:
ModuleUtils, PhoneNumberCU
Included in:
PhoneNumberCU
Defined in:
lib/ffaker/phone_number_cu.rb

Overview

Constant Summary collapse

MOBILE_OPERATORS_PREFIX =

Mobile prefixes

%w[05].freeze
HOME_WORK_OPERATORS_PREFIX =

Home or Work Operator prefixes

%w[
  021 022 023 024 031 032 033 041 042 043 045 046 047 048 07
].freeze
OPERATORS_PREFIX =
MOBILE_OPERATORS_PREFIX + HOME_WORK_OPERATORS_PREFIX

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

#country_codeObject

Country Code is E.164 Country Code



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

def country_code
  e164_country_code
end

#e164_country_codeObject

E.164 formats Based on information from en.wikipedia.org/wiki/E.164



92
93
94
# File 'lib/ffaker/phone_number_cu.rb', line 92

def e164_country_code
  '53'
end

#e164_home_work_phone_numberObject



100
101
102
103
104
105
106
# File 'lib/ffaker/phone_number_cu.rb', line 100

def e164_home_work_phone_number
  phone_prefix = home_work_phone_prefix
  case phone_prefix.size
  when 2 then FFaker.numerify("#{e164_country_code}#{phone_prefix[1]}#######")
  when 3 then FFaker.numerify("#{e164_country_code}#{phone_prefix[1, 2]}######")
  end
end

#e164_mobile_phone_numberObject



96
97
98
# File 'lib/ffaker/phone_number_cu.rb', line 96

def e164_mobile_phone_number
  FFaker.numerify("#{country_code}#{mobile_phone_prefix[1]}#######")
end

#e164_phone_numberObject



108
109
110
# File 'lib/ffaker/phone_number_cu.rb', line 108

def e164_phone_number
  rand(0..1).zero? ? e164_mobile_phone_number : e164_home_work_phone_number
end

#general_phone_numberObject

Generates general number



57
58
59
# File 'lib/ffaker/phone_number_cu.rb', line 57

def general_phone_number
  rand(0..1).zero? ? home_work_phone_number : mobile_phone_number
end

#home_work_phone_numberObject

Generates a general phone number (0x) xxx xxxx or (0xx) xx xxxx



40
41
42
43
44
45
46
# File 'lib/ffaker/phone_number_cu.rb', line 40

def home_work_phone_number
  phone_prefix = home_work_phone_prefix
  case phone_prefix.size
  when 2 then FFaker.numerify("(#{phone_prefix}) ### ####")
  when 3 then FFaker.numerify("(#{phone_prefix}) ## ####")
  end
end

#home_work_phone_prefixObject

Return a prefix in HOME_WORK_OPERATORS_PREFIX



29
30
31
# File 'lib/ffaker/phone_number_cu.rb', line 29

def home_work_phone_prefix
  fetch_sample(HOME_WORK_OPERATORS_PREFIX)
end

#international_country_codeObject

International formats



69
70
71
# File 'lib/ffaker/phone_number_cu.rb', line 69

def international_country_code
  rand(0..1).zero? ? "00#{country_code}" : "+#{country_code}"
end

#international_home_work_phone_numberObject



77
78
79
80
81
82
83
# File 'lib/ffaker/phone_number_cu.rb', line 77

def international_home_work_phone_number
  phone_prefix = home_work_phone_prefix
  case phone_prefix.size
  when 2 then FFaker.numerify("#{international_country_code}#{phone_prefix[1]} ### ####")
  when 3 then FFaker.numerify("#{international_country_code}#{phone_prefix[1, 2]} ## ####")
  end
end

#international_mobile_phone_numberObject



73
74
75
# File 'lib/ffaker/phone_number_cu.rb', line 73

def international_mobile_phone_number
  FFaker.numerify("#{international_country_code}#{mobile_phone_prefix[1]} ### ####")
end

#international_phone_numberObject



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

def international_phone_number
  rand(0..1).zero? ? international_mobile_phone_number : international_home_work_phone_number
end

#mobile_phone_numberObject

Generates a mobile phone number 05 xxx xxxx



51
52
53
# File 'lib/ffaker/phone_number_cu.rb', line 51

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

#mobile_phone_prefixObject

Return a prefix in MOBILE_OPERATORS_PREFIX



22
23
24
# File 'lib/ffaker/phone_number_cu.rb', line 22

def mobile_phone_prefix
  fetch_sample(MOBILE_OPERATORS_PREFIX)
end

#phone_numberObject

Generates phone number



114
115
116
117
118
119
120
# File 'lib/ffaker/phone_number_cu.rb', line 114

def phone_number
  case rand(0..2)
  when 0 then general_phone_number
  when 1 then international_phone_number
  when 2 then e164_phone_number
  end
end

#phone_prefixObject



33
34
35
# File 'lib/ffaker/phone_number_cu.rb', line 33

def phone_prefix
  fetch_sample(OPERATORS_PREFIX)
end