Method: Phonelib::PhoneFormatter#area_code

Defined in:
lib/phonelib/phone_formatter.rb

#area_codeString|nil

returns area code of parsed number

Returns:

  • (String|nil)

    parsed phone area code if available



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/phonelib/phone_formatter.rb', line 89

def area_code
  return nil unless area_code_possible?

  format_match, _format_string = formatting_data
  take_group = 1
  if type == Core::MOBILE && Core::AREA_CODE_MOBILE_TOKENS[country] && \
     format_match[1] == Core::AREA_CODE_MOBILE_TOKENS[country]
    take_group = 2
  end
  format_match[take_group]
end