Sha256: bbc6c39831b348ee0f99e010d1eeafdf1f74c584bab775be5bbb187e74db4f4d
Contents?: true
Size: 801 Bytes
Versions: 5
Compression:
Stored size: 801 Bytes
Contents
class String # Add a method to the String class so we can easily format phone numbers. # This enables: # "31612341234".phony_formatted # => '06 12341234' # "31612341234".phony_formatted(:spaces => '-') # => '06-12341234' # To first normalize a String use: # "010-12341234".phony_formatted(:normalize => :NL) def phony_formatted(options = {}) normalize_country_code = options.delete(:normalize) s = (normalize_country_code ? PhonyRails.normalize_number(self, :country_code => normalize_country_code.to_s) : self.gsub(/\D/, '')) return if s.blank? Phony.formatted(s, options.reverse_merge(:format => :national)) end # The bang method def phony_formatted!(options = {}) replace(self.phony_formatted(options)) end end
Version data entries
5 entries across 5 versions & 1 rubygems