Class: FlatKit::FieldType::IntegerType

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

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

Methods included from DescendantTracker

#children, #find_child, #find_children, #inherited

Class Method Details

.coerce(data) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/flat_kit/field_type/integer_type.rb', line 24

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

.matches?(data) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/flat_kit/field_type/integer_type.rb', line 11

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

.type_nameObject



7
8
9
# File 'lib/flat_kit/field_type/integer_type.rb', line 7

def self.type_name
  "integer"
end