class GeojsonImport

Public Class Methods

new(data) click to toggle source

TODO: handle a File object instead of calling IO read/write directly

# File lib/charta/geojson_import.rb, line 5
def initialize(data)
  @shapes = nil
  @xml = data
end

Public Instance Methods

as_geojson() click to toggle source
# File lib/charta/geojson_import.rb, line 27
def as_geojson
  @shapes.to_json
end
shapes(options = {}) click to toggle source
# File lib/charta/geojson_import.rb, line 15
def shapes(options = {})
  options[:to] ||= :json

  @shapes = JSON.parse(@xml)

  if options[:to].equal? :json
    @shapes = @shapes.to_json
  elsif options[:to].equal? :string
    @shapes = @shapes.to_s
  end
end
valid?() click to toggle source
# File lib/charta/geojson_import.rb, line 10
def valid?
  shapes = JSON.parse(@xml)
  ::Charta::GeoJSON.valid?(shapes)
end