Class: TelephoneNumber::TimeZoneDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/telephone_number/time_zone_detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(phone_number) ⇒ TimeZoneDetector

Returns a new instance of TimeZoneDetector.



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

def initialize(phone_number)
  @phone_number = phone_number
end

Instance Attribute Details

#phone_numberObject (readonly)

Returns the value of attribute phone_number.



3
4
5
# File 'lib/telephone_number/time_zone_detector.rb', line 3

def phone_number
  @phone_number
end

#timezoneObject (readonly)

Returns the value of attribute timezone.



3
4
5
# File 'lib/telephone_number/time_zone_detector.rb', line 3

def timezone
  @timezone
end

Instance Method Details

#dataObject



16
17
18
# File 'lib/telephone_number/time_zone_detector.rb', line 16

def data
  @data ||= Marshal.load(File.binread(File.expand_path('../../../data/timezones/map_data.dat', __FILE__)))
end

#detect_timezoneObject



9
10
11
12
13
14
# File 'lib/telephone_number/time_zone_detector.rb', line 9

def detect_timezone
  normalized_number = build_normalized_number.dup
  timezone = nil
  (normalized_number.length - 2).times { break if timezone = data[normalized_number.chop!] }
  timezone.to_s.split('&').join(', ')
end