class GeojsonModel::Coder

Public Class Methods

dump(object) click to toggle source

takes an object and returns the value to be stored in the database

# File lib/geojson_model/coder.rb, line 12
def self.dump(object)
  object.to_json
end
load(value) click to toggle source

takes the database value and returns an instance of the GeojsonModel class

# File lib/geojson_model/coder.rb, line 7
def self.load(value)
  dispatch(JSON.load(value))
end

Private Class Methods

dispatch(data) click to toggle source

@param data [Hash]

# File lib/geojson_model/coder.rb, line 20
def self.dispatch(data)
  if hash.has_key?('geometries')
    GeometryCollection.new(data)
  elsif data.has_key?('coordinates')
    Geometry.new(data)
  elsif data.has_key?('features')
    FeatureCollection.new(data)
  elsif data.has_key?('properties')
    Feature.new(data)
  else
    raise TypeError
  end
end