class TelephoneNumber::Number

Attributes

country[R]
formatter[R]
geo_locator[R]
original_number[R]
parser[R]
time_zone_detector[R]

Public Class Methods

new(number, country = nil) click to toggle source
# File lib/telephone_number/number.rb, line 10
def initialize(number, country = nil)
  @original_number = TelephoneNumber.sanitize(number)
  @country = country ? Country.find(country) : detect_country
  @parser = Parser.new(self)
  @formatter = Formatter.new(self)
end

Public Instance Methods

location(locale = :en) click to toggle source
# File lib/telephone_number/number.rb, line 17
def location(locale = :en)
  return if !country || !valid?
  @geo_locator ||= GeoLocator.new(self, locale)
  @geo_locator.location
end
timezone() click to toggle source
# File lib/telephone_number/number.rb, line 23
def timezone
  return if !country || !valid?
  @time_zone_detector ||= TimeZoneDetector.new(self)
  @time_zone_detector.detect_timezone
end

Private Instance Methods

detect_country() click to toggle source
# File lib/telephone_number/number.rb, line 39
def detect_country
  eligible_countries.detect(&:main_country_for_code) || eligible_countries.first
end
eligible_countries() click to toggle source
# File lib/telephone_number/number.rb, line 31
def eligible_countries
  # note that it is entirely possible for two separate countries to use the same
  # validation scheme. Take Italy and Vatican City for example.
  Country.all_countries.select do |country|
    original_number.start_with?(country.country_code) && self.class.new(original_number, country.country_id).valid?
  end
end