Sha256: 93acfa48a5162d39341e41f53e2ca683990318892ba124de353a84933eaa7d81

Contents?: true

Size: 521 Bytes

Versions: 1

Compression:

Stored size: 521 Bytes

Contents

module Compel
  module Coercion

    class Date < Type

      def coerce!
        format = options[:format] || '%Y-%m-%d'

        if value.is_a?(::Date)
          @value = value.strftime(format)
        end

        coerced = ::Date.strptime(value, format)

        if coerced.strftime(format) == value
          return coerced
        end

        fail

        rescue
          raise \
            Compel::TypeError,
            "'#{value}' is not a parsable date with format: #{format}"
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
compel-0.2.0 lib/compel/coercion/date.rb