lib/phonelib/phone_analyzer_helper.rb in phonelib-0.6.9 vs lib/phonelib/phone_analyzer_helper.rb in phonelib-0.6.10

- old
+ new

@@ -1,9 +1,23 @@ module Phonelib # @private helper methods for analyser module PhoneAnalyzerHelper private + def vanity_converted(phone) + return phone unless Phonelib.vanity_conversion + + (phone || '').gsub(/[a-z]/i.freeze) do |c| + c.upcase! + # subtract "A" + n = (c.ord - 65) / 3 + # account for #7 & #9 which have 4 chars + n -= 1 if c == 'S'.freeze || c == 'V'.freeze || c >= 'Y'.freeze + (n + 2).to_s + end + end + + # defines if to validate against single country or not def passed_country(country) code = country_prefix(country) if @original.start_with?('+') && code && !sanitized.start_with?(code) # in case number passed with + but it doesn't start with passed