Module: Csv2schema::Schema

Included in:
CSV
Defined in:
lib/csv2schema/schema.rb

Instance Method Summary collapse

Instance Method Details

#get_type(format) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/csv2schema/schema.rb', line 21

def get_type(format)
  {
    string: 'http://www.w3.org/2001/XMLSchema#string',
    numeric: 'http://www.w3.org/2001/XMLSchema#int',
    float: 'http://www.w3.org/2001/XMLSchema#float',
    uri: 'http://www.w3.org/2001/XMLSchema#anyURI',
    boolean: 'http://www.w3.org/2001/XMLSchema#boolean',
    date_db: 'http://www.w3.org/2001/XMLSchema#date',
    dateTime_iso8601: 'http://www.w3.org/2001/XMLSchema#dateTime',
    date_month: 'http://www.w3.org/2001/XMLSchema#gYearMonth',
    dateTime_hms: 'http://www.w3.org/2001/XMLSchema#time'
  }[format]
end

#schemaObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/csv2schema/schema.rb', line 4

def schema
  fields = @column_headers.map do |key,col|
    {
      name: col['name'],
      title: col['name'],
      constraints: {
        required: col['required'],
        type: get_type(col['format'])
      }
    }
  end

  {
    "fields": fields
  }.to_json
end