Class: GeojsonImport

Inherits:
Object
  • Object
show all
Defined in:
lib/charta/geojson_import.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ GeojsonImport

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


5
6
7
8
# File 'lib/charta/geojson_import.rb', line 5

def initialize(data)
  @shapes = nil
  @xml = data
end

Instance Method Details

#as_geojsonObject


27
28
29
# File 'lib/charta/geojson_import.rb', line 27

def as_geojson
  @shapes.to_json
end

#shapes(options = {}) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
# 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?Boolean

Returns:

  • (Boolean)

10
11
12
13
# File 'lib/charta/geojson_import.rb', line 10

def valid?
  shapes = JSON.parse(@xml)
  ::Charta::GeoJSON.valid?(shapes)
end