Sha256: 1dda7750a4350a358672fc33efe81a85b13cfed4d8d9febf34a0844e447a0440

Contents?: true

Size: 1003 Bytes

Versions: 5

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

require 'avromatic/model/types/abstract_type'

module Avromatic
  module Model
    module Types
      class FloatType < AbstractType
        VALUE_CLASSES = [::Float].freeze
        INPUT_CLASSES = [::Float, ::Integer].freeze

        def value_classes
          VALUE_CLASSES
        end

        def input_classes
          INPUT_CLASSES
        end

        def name
          'float'
        end

        def coerce(input)
          if input.nil? || input.is_a?(::Float)
            input
          elsif input.is_a?(::Integer)
            input.to_f
          else
            raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}")
          end
        end

        def coercible?(input)
          input.nil? || input.is_a?(::Float) || input.is_a?(::Integer)
        end

        def coerced?(input)
          input.nil? || input.is_a?(::Float)
        end

        def serialize(value, **)
          value
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
avromatic-2.2.1 lib/avromatic/model/types/float_type.rb
avromatic-2.2.0 lib/avromatic/model/types/float_type.rb
avromatic-2.1.0 lib/avromatic/model/types/float_type.rb
avromatic-2.0.1 lib/avromatic/model/types/float_type.rb
avromatic-2.0.0 lib/avromatic/model/types/float_type.rb