module Phony::Vanity
Helper module that maps vanity numbers to digit numbers.
Public Class Methods
Source
# File lib/phony/vanity.rb, line 9 def self.mapping @@mapping ||= %w[ ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 2223334445556667777888999922233344455566677778889999 ] end
Returns a char to number mapping string for the String#tr method.
Source
# File lib/phony/vanity.rb, line 33 def self.normalized(number) number.gsub @@vanity_normalizing_regexp, '' end
Source
# File lib/phony/vanity.rb, line 18 def self.replace(number) number.tr(*mapping) end
Replaces (and normalizes) vanity characters of passed number with correct digits.
Source
# File lib/phony/vanity.rb, line 26 def self.vanity?(number) !(normalized(number) =~ @@vanity_regexp).nil? end