Sha256: f49b460bc549073a3f937cc18091cd4888e4d1d9990e7c5961b2162c765d28f9

Contents?: true

Size: 728 Bytes

Versions: 7

Compression:

Stored size: 728 Bytes

Contents

# frozen_string_literal: true

module Acfs::Resource::Attributes
  # @api public
  #
  # Float attribute type. Use it in your model as an attribute type:
  #
  # @example
  #   class User < Acfs::Resource
  #     attribute :name, :float
  #   end
  #
  class Float < Base
    # @api public
    #
    # Cast given object to float.
    #
    # @param [Object] value Object to cast.
    # @return [Float] Casted object as float.
    #
    def cast_value(value)
      return 0.0 if value.blank?

      case value
        when ::Float then value
        when 'Infinity' then ::Float::INFINITY
        when '-Infinity' then -::Float::INFINITY
        when 'NaN' then ::Float::NAN
        else Float(value)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
acfs-2.0.0 lib/acfs/resource/attributes/float.rb
acfs-1.7.0 lib/acfs/resource/attributes/float.rb
acfs-1.6.0 lib/acfs/resource/attributes/float.rb
acfs-1.5.1 lib/acfs/resource/attributes/float.rb
acfs-1.5.0 lib/acfs/resource/attributes/float.rb
acfs-1.4.0 lib/acfs/resource/attributes/float.rb
acfs-1.3.4 lib/acfs/resource/attributes/float.rb