Sha256: 81cf20dee2936b9775e20409f806f515993e834d9616596df1686a24925d5314

Contents?: true

Size: 505 Bytes

Versions: 2

Compression:

Stored size: 505 Bytes

Contents

# typed: strict

module Typed
  module Coercion
    class FloatCoercer
      extend T::Sig
      extend T::Generic

      extend Coercer

      Target = type_template { {fixed: Float} }

      sig { override.params(field: Field, value: Value).returns(Result[Target, CoercionError]) }
      def self.coerce(field:, value:)
        Success.new(Float(value))
      rescue ArgumentError, TypeError
        Failure.new(CoercionError.new("'#{value}' cannot be coerced into Float."))
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sorbet-schema-0.1.1 lib/typed/coercion/float_coercer.rb
sorbet-schema-0.1.0 lib/typed/coercion/float_coercer.rb