Module: Roqua::Healthy::A19::PhoneValidator
- Defined in:
- lib/roqua/healthy/a19/phone_validator.rb
Constant Summary collapse
- EU_COUNTRY_CODES =
Set.new( %w[AT BE BG CY CZ DE DK EE EL ES FI FR HR HU IE IT LT LU LV MT NL PL PT RO SE SI SK UK] )
Class Method Summary collapse
- .contains_only_phone_number_characters?(number) ⇒ Boolean
- .phone_cell_number?(number) ⇒ Boolean
- .phone_cell_number_in_european_country?(number) ⇒ Boolean
- .strip_non_phone_number_characters(number) ⇒ Object
Class Method Details
.contains_only_phone_number_characters?(number) ⇒ Boolean
26 27 28 |
# File 'lib/roqua/healthy/a19/phone_validator.rb', line 26 def self.contains_only_phone_number_characters?(number) /^\+?\d+$/.match(number).present? end |
.phone_cell_number?(number) ⇒ Boolean
13 14 15 16 17 18 |
# File 'lib/roqua/healthy/a19/phone_validator.rb', line 13 def self.phone_cell_number?(number) stripped_number = strip_non_phone_number_characters(number) phone_cell_number_in_european_country?(stripped_number) && contains_only_phone_number_characters?(stripped_number) end |
.phone_cell_number_in_european_country?(number) ⇒ Boolean
20 21 22 23 24 |
# File 'lib/roqua/healthy/a19/phone_validator.rb', line 20 def self.phone_cell_number_in_european_country?(number) phone = Phonelib.parse(number, 'NL') phone.type == :mobile && EU_COUNTRY_CODES.include?(phone.country) end |
.strip_non_phone_number_characters(number) ⇒ Object
30 31 32 |
# File 'lib/roqua/healthy/a19/phone_validator.rb', line 30 def self.strip_non_phone_number_characters(number) number.gsub(/[-\s\.]/, '') end |