Class: Barometer::Data::ZoneCode

Inherits:
Object
  • Object
show all
Defined in:
lib/barometer/data/zone.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zone, time_class = ::Time) ⇒ ZoneCode

Returns a new instance of ZoneCode



104
105
106
107
# File 'lib/barometer/data/zone.rb', line 104

def initialize(zone, time_class=::Time)
  @zone = zone
  @time_class = time_class
end

Class Method Details

.detect?(zone) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/barometer/data/zone.rb', line 100

def self.detect?(zone)
  zone.respond_to?(:to_s) && Utils::ZoneCodeLookup.exists?(zone.to_s)
end

Instance Method Details

#codeObject



109
110
111
# File 'lib/barometer/data/zone.rb', line 109

def code
  zone
end

#local_to_utc(local_time) ⇒ Object



125
126
127
# File 'lib/barometer/data/zone.rb', line 125

def local_to_utc(local_time)
  local_time - offset
end

#nowObject



117
118
119
# File 'lib/barometer/data/zone.rb', line 117

def now
  time_class.now.utc + offset
end

#offsetObject



113
114
115
# File 'lib/barometer/data/zone.rb', line 113

def offset
  Utils::ZoneCodeLookup.offset(zone)
end

#to_sObject



121
122
123
# File 'lib/barometer/data/zone.rb', line 121

def to_s
  zone
end

#utc_to_local(utc_time) ⇒ Object



129
130
131
# File 'lib/barometer/data/zone.rb', line 129

def utc_to_local(utc_time)
  utc_time + offset
end