Sha256: 0d7db4c19eda7b6bcf2859f2cdffb370cb7101a10b6db4ed6c84a5ce669b12a1

Contents?: true

Size: 649 Bytes

Versions: 2

Compression:

Stored size: 649 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module Mixture
  module Coerce
    # Handles coercion of the DateTime class.
    class DateTime < Base
      type Types::DateTime

      coerce_to(Types::Object, Itself)
      coerce_to(Types::String, :to_s)
      coerce_to(Types::Time, :to_time)
      coerce_to(Types::Date, :to_date)
      coerce_to(Types::DateTime, :to_datetime)
      coerce_to(Types::Array) { |value| value.to_time.to_a }
      coerce_to(Types::Float) { |value| value.to_time.to_f }
      coerce_to(Types::Integer) { |value| value.to_time.to_i }
      coerce_to(Types::Rational) { |value| value.to_time.to_r }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mixture-0.7.1 lib/mixture/coerce/datetime.rb
mixture-0.7.0 lib/mixture/coerce/datetime.rb