File: phone_number_nl.rb

package info (click to toggle)
ruby-ffaker 2.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,776 kB
  • sloc: ruby: 12,788; makefile: 8; sh: 1
file content (46 lines) | stat: -rw-r--r-- 1,256 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

module FFaker
  module PhoneNumberNL
    extend ModuleUtils
    extend self

    COUNTRY_CODE = '+31'
    AREA_CODE_PREFIX = '0'
    PHONE_NUMBER = {
      2 => ['#######', '### ####', '#### ###'],
      3 => ['######', '#### ##', '## ## ##']
    }.freeze
    MOBILE_PHONE_NUMBER = ['########', ' ## ## ## ##', ' ### ### ##', ' #### ####'].freeze

    def phone_number
      return home_work_phone_number if rand(0..1).zero?

      mobile_phone_number
    end

    def home_work_phone_number
      area = fetch_sample(AREA_CODES)
      FFaker.numerify "#{AREA_CODE_PREFIX}#{area}-#{fetch_sample(PHONE_NUMBER[area.size])}"
    end

    def mobile_phone_number
      FFaker.numerify "#{AREA_CODE_PREFIX}6#{fetch_sample(MOBILE_PHONE_NUMBER)}"
    end

    def international_phone_number
      return international_mobile_phone_number if rand(0..1).zero?

      international_home_work_phone_number
    end

    def international_home_work_phone_number
      area = fetch_sample(AREA_CODES)
      FFaker.numerify("#{COUNTRY_CODE} #{area}-#{fetch_sample(PHONE_NUMBER[area.size])}")
    end

    def international_mobile_phone_number
      FFaker.numerify("#{COUNTRY_CODE} 6#{fetch_sample(MOBILE_PHONE_NUMBER)}")
    end
  end
end