Sha256: 9554923665207c6e375d5261c46dc237f9561d275f6d98fefa98c455539202cc

Contents?: true

Size: 454 Bytes

Versions: 31

Compression:

Stored size: 454 Bytes

Contents

module Superstore
  module Types
    class DateType < BaseType
      FORMAT = '%Y-%m-%d'
      REGEX = /\A\d{4}-\d{2}-\d{2}\Z/

      def encode(value)
        raise ArgumentError.new("#{value.inspect} is not a Date") unless value.kind_of?(Date)
        value.strftime(FORMAT)
      end

      def decode(str)
        return nil if str.empty?
        Date.parse(str)
      end

      def typecast(value)
        value.to_date
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
superstore-2.4.4 lib/superstore/types/date_type.rb
superstore-2.4.3 lib/superstore/types/date_type.rb
superstore-2.4.2 lib/superstore/types/date_type.rb
superstore-2.4.1 lib/superstore/types/date_type.rb
superstore-2.4.0 lib/superstore/types/date_type.rb
superstore-2.3.0 lib/superstore/types/date_type.rb
superstore-2.2.0 lib/superstore/types/date_type.rb
superstore-2.1.3 lib/superstore/types/date_type.rb
superstore-2.1.2 lib/superstore/types/date_type.rb
superstore-2.1.1 lib/superstore/types/date_type.rb
superstore-2.1.0 lib/superstore/types/date_type.rb
superstore-2.0.1 lib/superstore/types/date_type.rb
superstore-2.0.0 lib/superstore/types/date_type.rb
superstore-1.2.0 lib/superstore/types/date_type.rb
superstore-1.1.4 lib/superstore/types/date_type.rb
superstore-1.1.3 lib/superstore/types/date_type.rb
superstore-1.1.2 lib/superstore/types/date_type.rb
superstore-1.1.1 lib/superstore/types/date_type.rb
superstore-1.1.0 lib/superstore/types/date_type.rb
superstore-1.0.12 lib/superstore/types/date_type.rb