Sha256: db0131588e379ef88d3fe03385f336ab9cd0d6dfc27bb67804d92bc9f007b402

Contents?: true

Size: 608 Bytes

Versions: 3

Compression:

Stored size: 608 Bytes

Contents

# encoding: utf-8

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

      coerce_to(Types::Object, Itself)
      coerce_to(Types::String, :to_s)
      coerce_to(Types::Float, Itself)
      coerce_to(Types::Integer, :to_i)
      coerce_to(Types::Rational, :to_r)
      coerce_to(Types::Boolean) { |value| !value.zero? }
      coerce_to(Types::Time) { |value| ::Time.at(value) }
      coerce_to(Types::Date) { |value| ::Time.at(value).to_date }
      coerce_to(Types::DateTime) { |value| ::Time.at(value).to_datetime }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mixture-0.6.2 lib/mixture/coerce/float.rb
mixture-0.6.1 lib/mixture/coerce/float.rb
mixture-0.6.0 lib/mixture/coerce/float.rb