Sha256: a9ba74a040d4bb8051e9de5f612116ad13a2cd26fcf1ae3f4f0238bc233a55b2

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

module FFakerTW
  module PhoneNumberSN
    extend ModuleUtils
    extend self

    # Mobile Operator prefixes
    #
    #  77 =>  Orange
    #  76 =>  Tigo
    #  70 =>  Expresso
    #
    MOBILE_OPERATORS_PREFIX = %w[70 76 77].freeze

    # Home or Work Operator prefixes
    #
    #  33 =>  Orange
    #
    HOME_WORK_OPERATORS_PREFIX = %w[33].freeze

    # Return a prefix in MOBILE_OPERATORS_PREFIX
    # @see FFakerTW::PhoneNumberSN::MOBILE_OPERATORS_PREFIX
    #
    def mobile_phone_prefix
      fetch_sample(MOBILE_OPERATORS_PREFIX)
    end

    # Return a prefix in HOME_WORK_OPERATORS_PREFIX
    # @see FFakerTW::PhoneNumberSN::HOME_WORK_OPERATORS_PREFIX
    #
    def homework_phone_prefix
      fetch_sample(HOME_WORK_OPERATORS_PREFIX)
    end

    # Pattern that can be combined with a prefix to generate mobile, office phone_numbers
    # Example 745 77 99
    # Example 245 07 00
    # Example 726 29 05
    #
    def short_phone_number
      FFakerTW.numerify('###-##-##')
    end

    # Generates a mobile phone number
    # Example 70 745 77 99
    # Example 76 245 07 00
    # Example 77 726 29 05
    #
    def mobile_number
      "#{mobile_phone_prefix}-#{short_phone_number}"
    end

    # Generates a home or work phone number
    # Example 33 845 77 99
    # Example 33 945 07 00
    # Example 33 906 29 05
    #
    def homework_number
      "#{homework_phone_prefix}-#{rand(8..9)}#{FFakerTW.numerify('##-##-##')}"
    end

    # Generates a random phone number mobile or home or work
    #
    def phone_number
      return homework_number if rand(0..1).zero?

      mobile_number
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffakerTW-0.1.0 lib/ffakerTW/phone_number_sn.rb