Class: TableSchema::Types::GeoJSON

Inherits:
Base
  • Object
show all
Defined in:
lib/tableschema/types/geojson.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cast, #initialize, #test

Methods included from Helpers

#deep_symbolize_keys, #get_class_for_type, #type_class_lookup

Constructor Details

This class inherits a constructor from TableSchema::Types::Base

Class Method Details

.supported_constraintsObject



9
10
11
12
13
14
15
16
# File 'lib/tableschema/types/geojson.rb', line 9

def self.supported_constraints
  [
    'required',
    'unique',
    'pattern',
    'enum'
  ]
end

Instance Method Details

#cast_default(value) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/tableschema/types/geojson.rb', line 22

def cast_default(value)
  parsed_value = parse_value(value)
  JSON::Validator.validate!(geojson_schema, parsed_value)
  parsed_value
rescue JSON::Schema::ValidationError, JSON::ParserError
  raise TableSchema::InvalidGeoJSONType.new("#{value} is not valid GeoJSON")
end

#cast_topojson(value) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/tableschema/types/geojson.rb', line 30

def cast_topojson(value)
  parsed_value = parse_value(value)
  JSON::Validator.validate!(topojson_schema, parsed_value)
  parsed_value
rescue JSON::Schema::ValidationError, JSON::ParserError
  raise TableSchema::InvalidTopoJSONType.new("#{value} is not valid TopoJSON")
end

#nameObject



5
6
7
# File 'lib/tableschema/types/geojson.rb', line 5

def name
  'geojson'
end

#typeObject



18
19
20
# File 'lib/tableschema/types/geojson.rb', line 18

def type
  ::Hash
end