2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-03-01 16:42:46 +01:00
|
|
|
# Class extensions to the Phonelib module, which allow parsing using several countries at once.
|
|
|
|
module Phonelib
|
|
|
|
# Variation of `.valid_for_country`, that can check several countries at once.
|
|
|
|
def self.valid_for_countries?(value, countries)
|
|
|
|
countries.any? { |country| valid_for_country?(value, country) }
|
|
|
|
end
|
|
|
|
|
|
|
|
# Variation of `Phonelib.parse`, which parses the given string using the first country
|
|
|
|
# for which the phone number is valid.
|
|
|
|
def self.parse_for_countries(value, passed_countries = [])
|
|
|
|
valid_country = passed_countries.find { |country| valid_for_country?(value, country) }
|
|
|
|
parse(value, valid_country)
|
|
|
|
end
|
|
|
|
end
|