Module: TableSchema::Helpers

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

Instance Method Summary collapse

Instance Method Details

#deep_symbolize_keys(descriptor) ⇒ Object



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

def deep_symbolize_keys(descriptor)
  case descriptor
  when Hash
    descriptor.inject({}) do |new_descriptor, (key, val)|
      key_sym = key.respond_to?(:to_sym) ? key.to_sym : key
      new_descriptor[key_sym] = deep_symbolize_keys(val)
      new_descriptor
    end
  when Enumerable
    descriptor.map{ |el| deep_symbolize_keys(el)}
  else
    descriptor
  end
end

#get_class_for_type(type) ⇒ Object



19
20
21
# File 'lib/tableschema/helpers.rb', line 19

def get_class_for_type(type)
  "TableSchema::Types::#{type_class_lookup[type.to_sym] || 'String'}"
end

#type_class_lookupObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tableschema/helpers.rb', line 23

def type_class_lookup
  {
    any: 'Any',
    array: 'Array',
    base: 'Base',
    boolean: 'Boolean',
    date: 'Date',
    datetime: 'DateTime',
    geojson: 'GeoJSON',
    geopoint: 'GeoPoint',
    integer: 'Integer',
    number: 'Number',
    object: 'Object',
    string: 'String',
    time: 'Time',
    year: 'Year',
    yearmonth: 'YearMonth',
    duration: 'Duration',
  }
end