Module: Phonelib::PhoneAnalyzer

Includes:
PhoneAnalyzerHelper
Included in:
Phone
Defined in:
lib/phonelib/phone_analyzer.rb

Constant Summary collapse

NOT_FOR_CHECK =

array of types not included for validation check in cycle

[:general_desc, :fixed_line, :mobile, :fixed_or_mobile]

Instance Method Summary collapse

Instance Method Details

#analyze(phone, passed_country) ⇒ Object

parses provided phone if it is valid for country data and returns result of analyze

Attributes

  • phone - Phone number for parsing

  • passed_country - Country provided for parsing. Must be ISO code of country (2 letters) like ‘US’, ‘us’ or :us for United States



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/phonelib/phone_analyzer.rb', line 18

def analyze(phone, passed_country)
  country = country_or_default_country passed_country

  result = parse_country(phone, country)
  d_result = case
             when result && result.values.find { |e| e[:valid].any? }
               # all is good, return result
             when passed_country.nil?
               # trying for all countries if no country was passed
               detect_and_parse(phone, country)
             when country_can_dp?(country)
               # if country allows double prefix trying modified phone
               parse_country(changed_dp_phone(country, phone), country)
             end
  better_result(result, d_result)
end