Class: FlatKit::FieldType::FloatType

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

Constant Summary

Constants inherited from FlatKit::FieldType

CoerceFailure

Class Method Summary collapse

Methods inherited from FlatKit::FieldType

best_guess, candidate_types, weight

Methods included from DescendantTracker

#children, #find_child, #find_children, #inherited

Class Method Details

.coerce(data) ⇒ Object



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

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

.matches?(data) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.matches?(data)
  case data
  when Float
    true
  when Integer
    false
  when String
    return false if IntegerType.matches?(data)
    begin
      Float(data)
      true
    rescue ArgumentError => _
      false
    end
  else
    false
  end
end

.type_nameObject



5
6
7
# File 'lib/flat_kit/field_type/float_type.rb', line 5

def self.type_name
  "float"
end