Class: IknowParams::Serializer::Timezone

Inherits:
IknowParams::Serializer show all
Defined in:
lib/iknow_params/serializer.rb

Instance Attribute Summary

Attributes inherited from IknowParams::Serializer

#clazz

Instance Method Summary collapse

Methods inherited from IknowParams::Serializer

for, for!, json_value?, #matches_type!, #matches_type?, singleton

Constructor Details

#initializeTimezone

Returns a new instance of Timezone.



219
220
221
# File 'lib/iknow_params/serializer.rb', line 219

def initialize
  super(::TZInfo::Timezone)
end

Instance Method Details

#dump(val, json: nil) ⇒ Object



229
230
231
232
# File 'lib/iknow_params/serializer.rb', line 229

def dump(val, json: nil)
  matches_type!(val)
  val.identifier
end

#load(str) ⇒ Object



223
224
225
226
227
# File 'lib/iknow_params/serializer.rb', line 223

def load(str)
  TZInfo::Timezone.get(str)
rescue TZInfo::InvalidTimezoneIdentifier => _e
  raise LoadError.new("Invalid identifier for TZInfo zone: #{str}")
end