lib/phonelib/phone_analyzer.rb in phonelib-0.6.19 vs lib/phonelib/phone_analyzer.rb in phonelib-0.6.20

- old
+ new

@@ -44,10 +44,22 @@ return result if result.values.find { |e| e[:valid].any? } base_result end + # replacing national prefix to simplified format + def with_replaced_national_prefix(phone, data) + return phone unless data[Core::NATIONAL_PREFIX_TRANSFORM_RULE] + pattern = cr("^(?:#{data[Core::NATIONAL_PREFIX_FOR_PARSING]})") + match = phone.match pattern + if match && match.captures.compact.size > 0 + phone.gsub(pattern, data[Core::NATIONAL_PREFIX_TRANSFORM_RULE]) + else + phone + end + end + # trying to parse phone for single country including international prefix # check for provided country # # ==== Attributes # @@ -58,10 +70,10 @@ return nil unless data # if country was provided and it's a valid country, trying to # create e164 representation of phone number, # kind of normalization for parsing - e164 = convert_to_e164 phone, data + e164 = convert_to_e164 with_replaced_national_prefix(phone, data), data # if phone starts with international prefix of provided # country try to reanalyze without international prefix for # all countries return analyze(e164[1..-1], nil) if Core::PLUS_SIGN == e164[0] # trying to parse number for provided country