Class: FlatKit::FieldType::NullType

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

Overview

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

Constant Summary collapse

REGEX =
Regexp.union(/\A(null|nil)\Z/i, /\A\\N\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



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/flat_kit/field_type/null_type.rb', line 25

def self.coerce(data)
  case data
  when nil
    data
  when String
    return nil if REGEX.match?(data)

    CoerceFailure
  else
    CoerceFailure
  end
end

.matches?(data) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.type_nameObject



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

def self.type_name
  "null"
end