Sha256: 02fe7197992d90f1f2baa3810e808a755c548491ed59fc3c1e1e3f2e7d63d56b

Contents?: true

Size: 638 Bytes

Versions: 2

Compression:

Stored size: 638 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

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

2 entries across 2 versions & 1 rubygems

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