Class: ParamsReady::Value::DateCoder
- Inherits:
-
Coder
show all
- Defined in:
- lib/params_ready/value/coder.rb
Class Method Summary
collapse
Methods inherited from Coder
instance
Methods included from Coercion
#strict_default?, #try_coerce
value_class_name
#class_reader_writer
Class Method Details
.coerce(input, _) ⇒ Object
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/params_ready/value/coder.rb', line 173
def self.coerce(input, _)
return nil if input.nil? || input == ''
if input.is_a?(Numeric)
Time.at(input).to_date
elsif input.is_a?(String)
Date.parse(input)
elsif input.respond_to?(:to_date)
input.to_date
else
raise ParamsReadyError, "Unimplemented for type #{input.class.name}"
end
end
|
186
187
188
|
# File 'lib/params_ready/value/coder.rb', line 186
def self.format(value, format)
value.to_s
end
|