Sha256: 1513036ee4a74903901cd4252d4632458539a1e43ee513af6cc15a643a18a3ce
Contents?: true
Size: 1.68 KB
Versions: 4
Compression:
Stored size: 1.68 KB
Contents
# encoding: utf-8 module FFaker # Author: Gustavo Souza https://github.com/gustavor-souza # Source https://en.wikipedia.org/wiki/Telephone_numbers_in_Brazil # module PhoneNumberBR extend ModuleUtils extend self COUNTRY_PREFIX = '+55'.freeze AREA_CODE = %w(1# 2# 3# 4# 5# 6# 7# 8# 9#).freeze HOME_WORK_PHONE_PREFIX = %w(2 3 4 5).freeze MOBILE_PHONE_PREFIX = %w(6 7 8 9 96 97 98 99).freeze PHONE_NUMBER = %w(####### ###-####).freeze # generate a random phone number # def phone_number case rand(2) when 0 then home_work_phone_number when 1 then mobile_phone_number end end def home_work_phone_number number HOME_WORK_PHONE_PREFIX end def mobile_phone_number number MOBILE_PHONE_PREFIX end # pick a random phone number with the international prefix code # def international_phone_number case rand(2) when 0 then international_mobile_phone_number when 1 then international_home_work_phone_number end end def international_mobile_phone_number number MOBILE_PHONE_PREFIX, COUNTRY_PREFIX end def international_home_work_phone_number number HOME_WORK_PHONE_PREFIX, COUNTRY_PREFIX end def country_code COUNTRY_PREFIX end private def number(prefixes, country_prefix = '') space = random_space p = [ country_prefix, space, fetch_sample(AREA_CODE), space, fetch_sample(prefixes), fetch_sample(PHONE_NUMBER) ].join('').strip FFaker.numerify p end def random_space rand(2) == 1 ? ' ' : '' end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
ffaker-2.6.0 | lib/ffaker/phone_number_br.rb |
ffaker-2.5.0 | lib/ffaker/phone_number_br.rb |
ffaker-2.4.0 | lib/ffaker/phone_number_br.rb |
ffaker-2.3.0 | lib/ffaker/phone_number_br.rb |