Module: JsonTableSchema::Helpers

Included in:
Constraints, Infer, Schema, Types::Base
Defined in:
lib/jsontableschema/helpers.rb

Instance Method Summary collapse

Instance Method Details

#convert_to_boolean(value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/jsontableschema/helpers.rb', line 4

def convert_to_boolean(value)
  if value.is_a?(Boolean)
    return value
  elsif true_values.include?(value.to_s.downcase)
    true
  elsif false_values.include?(value.to_s.downcase)
    false
  else
    nil
  end
end

#false_valuesObject



20
21
22
# File 'lib/jsontableschema/helpers.rb', line 20

def false_values
  ['no', 'n', 'false', 'f', '0']
end

#get_class_for_type(type) ⇒ Object



24
25
26
# File 'lib/jsontableschema/helpers.rb', line 24

def get_class_for_type(type)
  "JsonTableSchema::Types::#{type_class_lookup[type]}"
end

#true_valuesObject



16
17
18
# File 'lib/jsontableschema/helpers.rb', line 16

def true_values
  ['yes', 'y', 'true', 't', '1']
end

#type_class_lookupObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jsontableschema/helpers.rb', line 28

def type_class_lookup
  {
    'any' => 'Any',
    'array' => 'Array',
    'base' => 'Base',
    'boolean' => 'Boolean',
    'date' => 'Date',
    'datetime' => 'DateTime',
    'geojson' => 'GeoJSON',
    'geopoint' => 'GeoPoint',
    'integer' => 'Integer',
    'null' => 'Null',
    'number' => 'Number',
    'object' => 'Object',
    'string' => 'String',
    'time' => 'Time',
  }
end