Module: FFaker::PhoneNumberCU

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

Overview

Author: Luilver<[email protected]> Based on information from en.wikipedia.org/wiki/Telephone_numbers_in_Cuba

Constant Summary collapse

MobileOperatorsPrefix =

Mobile prefixes

%w(05)
HomeWorkOperatorsPrefix =

Home or Work Operator prefixes

%w(021 022 023 024 031 032 033 041 042 043 045 046 047 048 07)
OperatorsPrefix =
MobileOperatorsPrefix + HomeWorkOperatorsPrefix

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore

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


98
99
100
# File 'lib/ffaker/phone_number_cu.rb', line 98

def e164_country_code
  '53'
end

#e164_home_work_phone_numberObject


106
107
108
109
110
111
112
# File 'lib/ffaker/phone_number_cu.rb', line 106

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


102
103
104
# File 'lib/ffaker/phone_number_cu.rb', line 102

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

#e164_phone_numberObject


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

def e164_phone_number
  case rand(2)
  when 0 then e164_mobile_phone_number
  when 1 then e164_home_work_phone_number
  end
end

#general_phone_numberObject

Generates general number


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

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

#home_work_phone_numberObject

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


37
38
39
40
41
42
43
# File 'lib/ffaker/phone_number_cu.rb', line 37

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 HomeWorkOperatorsPrefix


26
27
28
# File 'lib/ffaker/phone_number_cu.rb', line 26

def home_work_phone_prefix
  HomeWorkOperatorsPrefix[rand(HomeWorkOperatorsPrefix.size)]
end

#international_country_codeObject

International formats


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

def international_country_code
  case rand(2)
  when 0 then "00#{country_code}"
  when 1 then "+#{country_code}"
  end
end

#international_home_work_phone_numberObject


80
81
82
83
84
85
86
# File 'lib/ffaker/phone_number_cu.rb', line 80

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


76
77
78
# File 'lib/ffaker/phone_number_cu.rb', line 76

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

#international_phone_numberObject


88
89
90
91
92
93
# File 'lib/ffaker/phone_number_cu.rb', line 88

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

Generates a mobile phone number 05 xxx xxxx


48
49
50
# File 'lib/ffaker/phone_number_cu.rb', line 48

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

#mobile_phone_prefixObject

Return a prefix in MobileOperatorsPrefix


19
20
21
# File 'lib/ffaker/phone_number_cu.rb', line 19

def mobile_phone_prefix
  MobileOperatorsPrefix[rand(MobileOperatorsPrefix.size)]
end

#phone_numberObject

Generates phone number


123
124
125
126
127
128
129
# File 'lib/ffaker/phone_number_cu.rb', line 123

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

#phone_prefixObject


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

def phone_prefix
  OperatorsPrefix[rand(OperatorsPrefix.size)]
end