Sha256: d18a1225a66b868bb5a1dfc6c5ad9be7a52a98da4545a156517cb85cac583af4

Contents?: true

Size: 980 Bytes

Versions: 1

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true

require 'ph_no_to_word/error'

# TODO: for future use
module PhNoToWord
  # helper module to expand functionalities
  module Validator
    # Module methods
    module ClassMethods
      include Constants
      include Error

      def self.extended(base)
        base.send(:include, Constants)
      end

      # @param ph_no [String] ph_ary [Array]
      # Populate error if not a valid phone number given
      # Ex: ph_ary ["2", "2", "8", "2", "6", "6", "8", "6", "8", "7"]
      def validate(ph_no, ph_ary)
        raise RequiredArgumentMissingError, ERRORS[:missing_ph] if ph_no.empty?

        unless ph_no.length.eql?(PH_LENGTH)
          raise MalformattedArgumentError, ERRORS[:ph_length]
        end
        return if (ph_ary & FORBIDDEN_NOS).empty?

        raise MalformattedArgumentError, ERRORS[:malformed_ph_no]
      end
    end

    extend ClassMethods

    def self.included(base)
      base.extend(ClassMethods)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ph_no_to_word-2.0.0 lib/ph_no_to_word/validator.rb