Class: FlatKit::FieldType::IntegerType

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

Overview

Internal: Class reprepseting the Integer type and coercian to it.

Constant Summary collapse

REGEX =
/\A[-+]?\d+\Z/

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/integer_type.rb', line 27

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

.matches?(data) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.matches?(data)
  case data
  when Integer
    true
  when Float
    false
  when String
    REGEX.match?(data)
  else
    false
  end
end

.type_nameObject



10
11
12
# File 'lib/flat_kit/field_type/integer_type.rb', line 10

def self.type_name
  "integer"
end