diff --git a/lib/phonelib/phone_analyzer.rb b/lib/phonelib/phone_analyzer.rb index ded95ff..ff14624 100644 --- a/lib/phonelib/phone_analyzer.rb +++ b/lib/phonelib/phone_analyzer.rb @@ -139,7 +139,7 @@ def detect_and_parse(phone, country) end def country_code_candidates_for(phone) - stripped_phone = phone.gsub(/^(#{Phonelib.phone_data_int_prefixes})/, '') + stripped_phone = phone.gsub(cr("Phonelib.phone_data_int_prefixes") { /^(#{Phonelib.phone_data_int_prefixes})/ }, '') ((1..3).map { |length| phone[0, length] } + (1..3).map { |length| stripped_phone[0, length] }).uniq end diff --git a/lib/phonelib/phone_analyzer_helper.rb b/lib/phonelib/phone_analyzer_helper.rb index 2affe29..0eceb60 100644 --- a/lib/phonelib/phone_analyzer_helper.rb +++ b/lib/phonelib/phone_analyzer_helper.rb @@ -52,7 +52,7 @@ def country_prefix(country) # caches regular expression, reusing it for later lookups def cr(regexp) - Phonelib.phone_regexp_cache[regexp] ||= Regexp.new(regexp).freeze + Phonelib.phone_regexp_cache[regexp] ||= Regexp.new(block_given? ? yield(regexp) : regexp).freeze end # defines whether country can have double country prefix in number