Sha256: 966e15a074c1ed85e38454d68258f9e108a22b2e0e4a02fba33337c9d570abd1

Contents?: true

Size: 633 Bytes

Versions: 2

Compression:

Stored size: 633 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

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

      coerce_to(Types::Object, Itself)
      coerce_to(Types::String, :dup)
      coerce_to(Types::Symbol, :to_sym)
      coerce_to(Types::Integer, :to_i)
      coerce_to(Types::Float, :to_f)
      coerce_to(Types::Boolean) { |value| !value.empty? }
      coerce_to(Types::Time) { |value| ::Time.parse(value) }
      coerce_to(Types::Date) { |value| ::Date.parse(value) }
      coerce_to(Types::DateTime) { |value| ::DateTime.parse(value) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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