File: phone_number_ru.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 (120 lines) | stat: -rw-r--r-- 2,870 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# frozen_string_literal: true

module FFaker
  module PhoneNumberRU
    extend ModuleUtils
    extend self

    INTERNATIONAL_COUNTRY_PREFIX = '+7'
    COUNTRY_PREFIX = '8'
    TOLL_FREE_PREFIX = '800'

    # Generate general phone number with international country code
    #   +7 929 933 24 99
    #   +7 851 921 35 92
    #
    def international_phone_number
      case rand(0..1)
      when 0 then international_mobile_phone_number
      when 1 then international_home_work_phone_number
      end
    end

    # Generate mobile phone number with international country code
    #   +7 929 933 24 99
    #   +7 978 921 35 92
    #
    def international_mobile_phone_number
      build_phone_number(international_country_code, mobile_phone_prefix)
    end

    # Generate home or work phone number with international country code
    #   +7 842 933 24 99
    #   +7 851 921 35 92
    #
    def international_home_work_phone_number
      build_phone_number(international_country_code, home_work_phone_prefix)
    end

    # Generate toll free phone number with international country code
    #   +7 800 413 01 33
    #   +7 800 153 55 22
    #
    def international_toll_free_number
      build_phone_number(international_country_code, TOLL_FREE_PREFIX)
    end

    # Generate general phone number with internal country code
    #   8 999 044 31 33
    #   8 843 944 33 33
    #
    def phone_number
      case rand(0..1)
      when 0 then mobile_phone_number
      when 1 then home_work_phone_number
      end
    end

    # Generate mobile phone number with internal country code
    #   8 949 232 22 22
    #   8 999 331 23 12
    #
    def mobile_phone_number
      build_phone_number(country_code, mobile_phone_prefix)
    end

    # Generate home or work phone number with internal country code
    #   8 011 232 22 22
    #   8 836 331 23 12
    #
    def home_work_phone_number
      build_phone_number(country_code, home_work_phone_prefix)
    end

    # Generate toll free phone number with internal country code
    #   8 800 413 01 33
    #   8 800 153 55 22
    #
    def toll_free_number
      build_phone_number(country_code, TOLL_FREE_PREFIX)
    end

    # International country code
    #   +7
    #
    def international_country_code
      INTERNATIONAL_COUNTRY_PREFIX
    end

    # Internal country code
    #   8
    #
    def country_code
      COUNTRY_PREFIX
    end

    # Home or work phone prefix
    #  081
    #  301
    #
    def home_work_phone_prefix
      fetch_sample(HOME_PHONE_PREFIXES)
    end

    # Mobile phone prefix
    #  929
    #  978
    #
    def mobile_phone_prefix
      fetch_sample(MOBILE_PHONE_PREFIXES)
    end

    private

    # Build phone number by country_code and prefix
    #
    def build_phone_number(country_code, prefix)
      "#{country_code} #{prefix} #{FFaker.numerify('###-##-##')}"
    end
  end
end