class TableSchema::Types::GeoJSON

Public Class Methods

supported_constraints() click to toggle source
# File lib/tableschema/types/geojson.rb, line 9
def self.supported_constraints
  [
    'required',
    'unique',
    'pattern',
    'enum'
  ]
end

Public Instance Methods

cast_default(value) click to toggle source
# 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) click to toggle source
# 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
name() click to toggle source
# File lib/tableschema/types/geojson.rb, line 5
def name
  'geojson'
end
type() click to toggle source
# File lib/tableschema/types/geojson.rb, line 18
def type
  ::Hash
end

Private Instance Methods

geojson_schema() click to toggle source
# File lib/tableschema/types/geojson.rb, line 48
def geojson_schema
  path = File.join( File.dirname(__FILE__), "..", "..", "profiles", "geojson.json" )
  JSON.parse(File.read(path), symbolize_names: true)
end
parse_value(value) click to toggle source
# File lib/tableschema/types/geojson.rb, line 40
def parse_value(value)
  if value.is_a?(type)
    value
  else
    JSON.parse(value, symbolize_names: true)
  end
end
topojson_schema() click to toggle source
# File lib/tableschema/types/geojson.rb, line 53
def topojson_schema
  path = File.join( File.dirname(__FILE__), "..", "..", "profiles", "topojson.json" )
  JSON.parse(File.read(path), symbolize_names: true)
end