Sha256: d5df9f0c8a9b2c87cfd2e76a51d817101380afb251eefc6458b047013d33f70b

Contents?: true

Size: 603 Bytes

Versions: 3

Compression:

Stored size: 603 Bytes

Contents

# encoding: utf-8

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

3 entries across 3 versions & 1 rubygems

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