Class: Shale::Type::Float

Inherits:
Value
  • Object
show all
Defined in:
lib/shale/type/float.rb

Overview

Cast value to Float

Class Method Summary collapse

Methods inherited from Value

as_csv, as_hash, as_json, as_toml, as_xml, as_xml_value, as_yaml, of_csv, of_hash, of_json, of_toml, of_xml, of_yaml

Class Method Details

.cast(value) ⇒ Float?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • value (#to_f, String, nil)

    Value to cast

Returns:



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/shale/type/float.rb', line 16

def self.cast(value)
  return if value.nil?

  case value
  when ::Float then value
  when 'Infinity' then ::Float::INFINITY
  when '-Infinity' then -::Float::INFINITY
  when 'NaN' then ::Float::NAN
  else value.to_f
  end
end