class AutoTimezone::Sundial
Public Class Methods
new(ctx)
click to toggle source
# File lib/auto_timezone/sundial.rb, line 3 def initialize(ctx) @ctx = ctx return if !config.default_timezone_block || @ctx.respond_to?(:auto_timezone_default) @ctx.define_singleton_method :auto_timezone_default, config.default_timezone_block end
preferred_zones()
click to toggle source
# File lib/auto_timezone/sundial.rb, line 13 def self.preferred_zones @preferred_zones ||= AutoTimezone.config.preferred_timezones.map { |z| Time.find_zone(z) } end
Public Instance Methods
current_timezone()
click to toggle source
# File lib/auto_timezone/sundial.rb, line 9 def current_timezone @current_timezone ||= Time.find_zone(timezone_name) end
Private Instance Methods
config()
click to toggle source
# File lib/auto_timezone/sundial.rb, line 40 def config AutoTimezone.config end
find_zone_by_offset(offset)
click to toggle source
# File lib/auto_timezone/sundial.rb, line 32 def find_zone_by_offset(offset) self.class.preferred_zones.find { |z| z.utc_offset == offset } || Time.find_zone(offset) end
timezone_from_config_block()
click to toggle source
# File lib/auto_timezone/sundial.rb, line 24 def timezone_from_config_block @ctx.auto_timezone_default if @ctx.respond_to?(:auto_timezone_default) end
timezone_from_offset()
click to toggle source
# File lib/auto_timezone/sundial.rb, line 28 def timezone_from_offset find_zone_by_offset(cookies[:auto_timezone_offset].presence.try(:to_i)).try(:name) end
timezone_name()
click to toggle source
# File lib/auto_timezone/sundial.rb, line 19 def timezone_name cookies[:auto_timezone] ||= timezone_from_config_block cookies[:auto_timezone] ||= timezone_from_offset end