Sha256: 1dc542b1412956bcf6fad6d401a0aef93885e08fefcc265cae47a0d935570f4a

Contents?: true

Size: 518 Bytes

Versions: 1

Compression:

Stored size: 518 Bytes

Contents

module Compel
  module Coercion

    class Time < Type

      def coerce!
        format = options[:format] || '%FT%T'

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

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

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

        fail

        rescue
          raise \
            Compel::TypeError,
            "'#{value}' is not a parsable time 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/time.rb