demarches-normaliennes/lib/core_ext/phonelib.rb
Pierre de La Morinerie 5150e33212 models: ensure DROM phone numbers are valid
They were accepted before, because they were 'possible' – but now
they are explicitely considered as valid.
2022-03-02 09:57:03 +00:00

14 lines
642 B
Ruby

# 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