Class: IknowParams::Serializer::ISO8601

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

Overview

Abstract serializer for ISO8601 dates and times

Direct Known Subclasses

Date, Duration, Time

Instance Attribute Summary

Attributes inherited from IknowParams::Serializer

#clazz

Instance Method Summary collapse

Methods inherited from IknowParams::Serializer

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

Constructor Details

This class inherits a constructor from IknowParams::Serializer

Instance Method Details

#dump(val, json: nil) ⇒ Object



187
188
189
190
# File 'lib/iknow_params/serializer.rb', line 187

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

#load(str) ⇒ Object



179
180
181
182
183
184
185
# File 'lib/iknow_params/serializer.rb', line 179

def load(str)
  raise TypeError.new unless str.is_a?(::String)

  clazz.parse(str)
rescue TypeError, ArgumentError => _e
  raise LoadError.new("Invalid type for conversion to #{clazz}")
end