Class: ParamsReady::Value::DateTimeCoder
- Inherits:
-
Coder
- Object
- Coder
- ParamsReady::Value::DateTimeCoder
show all
- Defined in:
- lib/params_ready/value/coder.rb
Class Method Summary
collapse
Methods inherited from Coder
strict_default?, try_coerce, value_class_name
#class_reader_writer
Class Method Details
.coerce(input, _) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/params_ready/value/coder.rb', line 163
def self.coerce(input, _)
return nil if input.nil? || input == ''
if input.is_a?(Numeric)
Time.at(input).to_datetime
elsif input.is_a?(String)
DateTime.parse(input)
elsif input.respond_to?(:to_datetime)
input.to_datetime
else
raise ParamsReadyError, "Unimplemented for type #{input.class.name}"
end
end
|
176
177
178
|
# File 'lib/params_ready/value/coder.rb', line 176
def self.format(value, format)
value.to_s
end
|