Class: TelephoneNumber::Number

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/telephone_number/number.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, country = nil) ⇒ Number

Returns a new instance of Number.



10
11
12
13
14
15
# 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

Instance Attribute Details

#countryObject (readonly)

Returns the value of attribute country.



5
6
7
# File 'lib/telephone_number/number.rb', line 5

def country
  @country
end

#formatterObject (readonly)

Returns the value of attribute formatter.



5
6
7
# File 'lib/telephone_number/number.rb', line 5

def formatter
  @formatter
end

#geo_locatorObject (readonly)

Returns the value of attribute geo_locator.



5
6
7
# File 'lib/telephone_number/number.rb', line 5

def geo_locator
  @geo_locator
end

#original_numberObject (readonly)

Returns the value of attribute original_number.



5
6
7
# File 'lib/telephone_number/number.rb', line 5

def original_number
  @original_number
end

#parserObject (readonly)

Returns the value of attribute parser.



5
6
7
# File 'lib/telephone_number/number.rb', line 5

def parser
  @parser
end

#time_zone_detectorObject (readonly)

Returns the value of attribute time_zone_detector.



5
6
7
# File 'lib/telephone_number/number.rb', line 5

def time_zone_detector
  @time_zone_detector
end

Instance Method Details

#location(locale = :en) ⇒ Object



17
18
19
20
21
# 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

#timezoneObject



23
24
25
26
27
# 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