Module: Phonelib::PhoneAnalyzer
- Included in:
- Phone
- Defined in:
- lib/phonelib/phone_analyzer.rb
Overview
phone analyzing methods module
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
-
#analyze(phone, passed_country) ⇒ Object
parses provided phone if it is valid for country data and returns result of analyze.
-
#cr(regexp) ⇒ Object
caches regular expression, reusing it for later lookups.
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
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/phonelib/phone_analyzer.rb', line 20 def analyze(phone, passed_country) country = country_or_default_country passed_country result = try_to_parse_single_country(phone, country) # if previous parsing failed, trying for all countries if result.nil? || result.empty? || result.values.first[:valid].empty? detected = detect_and_parse phone result = detected.empty? ? result || {} : detected end result end |
#cr(regexp) ⇒ Object
caches regular expression, reusing it for later lookups
8 9 10 |
# File 'lib/phonelib/phone_analyzer.rb', line 8 def cr(regexp) Phonelib.phone_regexp_cache[regexp] ||= Regexp.new(regexp) end |