Class: FlatKit::FieldType::FloatType

Inherits:
FlatKit::FieldType show all
Defined in:
lib/flat_kit/field_type/float_type.rb

Overview

Internal: Represeting floating point data and conversion to it

Constant Summary

Constants inherited from FlatKit::FieldType

CoerceFailure

Class Method Summary collapse

Methods inherited from FlatKit::FieldType

best_guess, candidate_types, weight, weights

Methods included from DescendantTracker

#children, #find_child, #find_children, #inherited

Class Method Details

.coerce(data) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/flat_kit/field_type/float_type.rb', line 27

def self.coerce(data)
  Float(data)
rescue TypeError => _e
  CoerceFailure
rescue ArgumentError => _e
  CoerceFailure
end

.matches?(data) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/flat_kit/field_type/float_type.rb', line 12

def self.matches?(data)
  case data
  when Float
    true
  when Integer
    false
  when String
    return false if IntegerType.matches?(data)

    maybe_float?(data)
  else
    false
  end
end

.maybe_float?(data) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/flat_kit/field_type/float_type.rb', line 35

def self.maybe_float?(data)
  Float(data)
  true
rescue ArgumentError => _e
  false
end

.type_nameObject



8
9
10
# File 'lib/flat_kit/field_type/float_type.rb', line 8

def self.type_name
  "float"
end