Sha256: 8c00207dc961999099965659bb2069250f9b7754a1365a361ab58a0f0bf1804b
Contents?: true
Size: 681 Bytes
Versions: 2
Compression:
Stored size: 681 Bytes
Contents
module Compel module Coercion class DateType < Type attr_reader :format def coerce_value @format = options[:format] || default_format if value.is_a?(klass) @value = value.strftime(format) end coerced = klass.strptime(value, format) if coerced.strftime(format) == value return coerced end build_error_result rescue build_error_result end def build_error_result custom_error = "'#{value}' is not a parsable #{klass.to_s.downcase} with format: #{format}" Result.new(nil, value, self.class, custom_error) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
compel-0.4.0 | lib/compel/coercion/types/date_type.rb |
compel-0.3.7 | lib/compel/coercion/types/date_type.rb |