Class: FlatKit::FieldType::UnknownType

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

Overview

Internal: Unknown type, this is what we use for unknown values in the data

Constant Summary collapse

REGEX =
%r{\A(na|n/a|unk|unknown)\Z}i

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



21
22
23
24
25
26
27
# File 'lib/flat_kit/field_type/unknown_type.rb', line 21

def self.coerce(data)
  return data if REGEX.match?(data)

  CoerceFailure
rescue StandardError
  CoerceFailure
end

.matches?(data) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/flat_kit/field_type/unknown_type.rb', line 14

def self.matches?(data)
  return false unless data.is_a?(String)
  return true if data.empty?

  REGEX.match?(data)
end

.type_nameObject



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

def self.type_name
  "unknown"
end