Module: Faker::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



65
66
67
# File 'lib/ffaker/phone_number_cu.rb', line 65

def country_code
  e164_country_code
end

#e164_country_codeObject

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



100
101
102
# File 'lib/ffaker/phone_number_cu.rb', line 100

def e164_country_code
  "53"
end

#e164_home_work_phone_numberObject



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

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

#e164_mobile_phone_numberObject



104
105
106
# File 'lib/ffaker/phone_number_cu.rb', line 104

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

#e164_phone_numberObject



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

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



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

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



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

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

#home_work_phone_prefixObject

Return a prefix in HomeWorkOperatorsPrefix



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

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

#international_country_codeObject

International formats



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

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



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

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

#international_mobile_phone_numberObject



78
79
80
# File 'lib/ffaker/phone_number_cu.rb', line 78

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

#international_phone_numberObject



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

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



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

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

#mobile_phone_prefixObject

Return a prefix in MobileOperatorsPrefix



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

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

#phone_numberObject

Generates phone number



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

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



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

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