Class: ProfileFieldTypes::Phone

Inherits:
ProfileField show all
Defined in:
app/models/profile_field_types/phone.rb

Overview

Phone Number Field

Class Method Summary collapse

Methods inherited from ProfileField

#children_count, #delete_cache, #display_html, #key, #label, #orig_profileable, possible_types, #profileable, #underscored_type, #value

Methods inherited from ActiveRecord::Base

#readonly?

Class Method Details

.format_phone_number(phone_number_str) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/profile_field_types/phone.rb', line 10

def self.format_phone_number( phone_number_str )
  return "" if phone_number_str.nil?
  value = phone_number_str

  # determine whether this is an international number
  format = :national
  format = :international if value.start_with?( "00" ) or value.start_with? ( "+" )

  # do only format international numbers, since for national numbers, the country
  # is unknown and each country formats its national area codes differently.
  if format == :international
    value = Phony.normalize( value ) # remove spaces etc.
    value = value[ 2..-1 ] if value.start_with?( "00" ) # because Phony can't handle leading 00
    value = value[ 1..-1 ] if value.start_with?( "+" ) # because Phony can't handle leading +
    value = Phony.formatted( value, :format => format, :spaces => ' ' )
  end
  
  return value
end

.model_nameObject



6
# File 'app/models/profile_field_types/phone.rb', line 6

def self.model_name; ProfileField.model_name; end