module TimezoneTeleporter

frozen_string_literal => true

Constants

TIMEZONE_LOCATIONS
VERSION

Public Class Methods

configuration() click to toggle source
# File lib/timezone_teleporter.rb, line 16
def configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/timezone_teleporter.rb, line 11
def configure
  self.configuration ||= Configuration.new
  yield(configuration)
end
teleport(lat_or_tz, lng=nil) click to toggle source
# File lib/timezone_teleporter.rb, line 20
def teleport(lat_or_tz, lng=nil)
  if lng.nil?
    teleport_timezone(lat_or_tz)
  else
    teleport_location(lat_or_tz, lng)
  end
end
teleport_location(lat, lng) click to toggle source
# File lib/timezone_teleporter.rb, line 28
def teleport_location(lat, lng)
  teleport_timezone(timezone_at(lat, lng))
rescue StandardError => e
  raise e unless configuration.silent_exceptions
end
teleport_timezone(timezone) click to toggle source
# File lib/timezone_teleporter.rb, line 34
def teleport_timezone(timezone)
  location = TIMEZONE_LOCATIONS[timezone]

  raise TimeZoneNotFoundError unless location || configuration.silent_exceptions

  location
end
timezone_at(lat, lng) click to toggle source
# File lib/timezone_teleporter.rb, line 42
def timezone_at(lat, lng)
  timezone_name = timezone_finder.timezone_at(lat: lat, lng: lng)

  timezone_name ||= timezone_finder.closest_timezone_at(lat: lat, lng: lng, delta_degree: configuration.delta_degree) if configuration.use_proximity_algorithm

  raise TimeZoneNotFoundError unless timezone_name

  timezone_name
end

Private Class Methods

timezone_finder() click to toggle source
# File lib/timezone_teleporter.rb, line 54
def timezone_finder
  @timezone_finder ||= TimezoneFinder.create
end