Sha256: c76fb9a3e42270a27c028bd7eefd20faffa52af7ed39dc660a1369af109cd677

Contents?: true

Size: 647 Bytes

Versions: 2

Compression:

Stored size: 647 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

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

      coerce_to(Types::Object, Itself)
      coerce_to(Types::Rational, Itself)
      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 }
      coerce_to(Types::Float, :to_f)
      coerce_to(Types::Integer, :to_i)
      coerce_to(Types::String, :to_s)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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