Class: Acfs::Resource::Attributes::Float

Inherits:
Base
  • Object
show all
Defined in:
lib/acfs/resource/attributes/float.rb

Overview

Float attribute type. Use it in your model as an attribute type:

Examples:

class User < Acfs::Resource
  attribute :name, :float
end

Instance Attribute Summary

Attributes inherited from Base

#default

Instance Method Summary collapse

Methods inherited from Base

#cast, #default_value, #initialize

Constructor Details

This class inherits a constructor from Acfs::Resource::Attributes::Base

Instance Method Details

#cast_value(value) ⇒ Float

Cast given object to float.

Parameters:

  • value (Object)

    Object to cast.

Returns:

  • (Float)

    Casted object as float.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/acfs/resource/attributes/float.rb', line 21

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