Class: TelephoneNumber::TimeZoneDetector
- Inherits:
-
Object
- Object
- TelephoneNumber::TimeZoneDetector
- Defined in:
- lib/telephone_number/time_zone_detector.rb
Instance Attribute Summary collapse
-
#phone_number ⇒ Object
readonly
Returns the value of attribute phone_number.
-
#timezone ⇒ Object
readonly
Returns the value of attribute timezone.
Instance Method Summary collapse
- #data ⇒ Object
- #detect_timezone ⇒ Object
-
#initialize(phone_number) ⇒ TimeZoneDetector
constructor
A new instance of TimeZoneDetector.
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_number ⇒ Object (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 |
#timezone ⇒ Object (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
#data ⇒ Object
16 17 18 |
# File 'lib/telephone_number/time_zone_detector.rb', line 16 def data @data ||= Marshal.load(File.binread(File.('../../../data/timezones/map_data.dat', __FILE__))) end |
#detect_timezone ⇒ Object
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 |