module RiceBubble class Attributes class Datetime < Base def valid?(value) return false unless valid_datetime?(value) value.respond_to?(:to_datetime) end def coerce(value) return nil unless valid_datetime?(value) value.respond_to?(:to_datetime) ? value.to_datetime : value end private def valid_datetime?(value) case value when ::Time then true when ::DateTime then true when ::Date then false else value.respond_to?(:to_datetime) end end end end end