Module: FFaker::PhoneNumberJA

Extended by:
ModuleUtils, PhoneNumberJA
Included in:
PhoneNumberJA
Defined in:
lib/ffaker/phone_number_ja.rb

Constant Summary collapse

JAPAN_PREFIX =
'0'
JAPAN_COUNTRY_CODE =
'+81'
ONE_DISIT_FORMAT =
'%s #### ####'
TWO_DISIT_FORMAT =
'%s ### ####'
THREE_DISIT_FORMAT =
'%s ## ####'
FOUR_DISIT_FORMAT =
'%s # ####'
MOBILE_PHONE_PREFIXES =
%w[90 80 70].freeze
IP_PHONE_PREFIX =
'50'
MOBILE_NUMBER_FORMAT =
'%s #### ####'

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

#home_phone_numberObject



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

def home_phone_number
  disit = rand(1..4)
  FFaker.numerify("#{JAPAN_PREFIX}#{home_phone_number_format(disit)}")
end

#home_phone_number_format(disit) ⇒ Object



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

def home_phone_number_format(disit)
  prefix = home_phone_prefix(disit)
  select_home_phone_format(disit) % prefix
end

#home_phone_prefix(disit = nil) ⇒ Object



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

def home_phone_prefix(disit = nil)
  case disit
  when 1 then fetch_sample(ONE_DISIT_AREA_CODES)
  when 2 then fetch_sample(TWO_DISIT_AREA_CODES)
  when 3 then fetch_sample(THREE_DISIT_AREA_CODES)
  when 4 then fetch_sample(FOUR_DISIT_AREA_CODES)
  end
end

#international_home_phone_numberObject



38
39
40
41
# File 'lib/ffaker/phone_number_ja.rb', line 38

def international_home_phone_number
  disit = rand(1..4)
  FFaker.numerify("#{JAPAN_COUNTRY_CODE} #{home_phone_number_format(disit)}")
end

#international_mobile_phone_numberObject



43
44
45
# File 'lib/ffaker/phone_number_ja.rb', line 43

def international_mobile_phone_number
  FFaker.numerify("#{JAPAN_COUNTRY_CODE} #{mobile_phone_number_format}")
end

#international_phone_numberObject



47
48
49
50
51
52
# File 'lib/ffaker/phone_number_ja.rb', line 47

def international_phone_number
  case rand(0..1)
  when 0 then international_mobile_phone_number
  when 1 then international_home_phone_number
  end
end

#mobile_phone_numberObject



27
28
29
# File 'lib/ffaker/phone_number_ja.rb', line 27

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

#mobile_phone_number_formatObject



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

def mobile_phone_number_format
  prefix = mobile_prefix
  MOBILE_NUMBER_FORMAT % prefix
end

#mobile_prefixObject



68
69
70
# File 'lib/ffaker/phone_number_ja.rb', line 68

def mobile_prefix
  fetch_sample(MOBILE_PHONE_PREFIXES)
end

#phone_numberObject



31
32
33
34
35
36
# File 'lib/ffaker/phone_number_ja.rb', line 31

def phone_number
  case rand(0..1)
  when 0 then home_phone_number
  when 1 then mobile_phone_number
  end
end