Class: ParamsReady::Value::DateCoder

Inherits:
Coder
  • Object
show all
Defined in:
lib/params_ready/value/coder.rb

Class Method Summary collapse

Methods inherited from Coder

value_class_name

Methods included from Extensions::ClassReaderWriter

#class_reader_writer

Methods included from Coercion

#strict_default?, #try_coerce

Class Method Details

.coerce(input, _) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/params_ready/value/coder.rb', line 145

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

.format(value, format) ⇒ Object



158
159
160
# File 'lib/params_ready/value/coder.rb', line 158

def self.format(value, format)
  value.to_s
end