libgd-gis 0.4.5 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cca40fe3f91685466e2c0ba2d8baea43032ed49d53901efcaf55721e96eac99
4
- data.tar.gz: 691682c8ba0207ab1e57f6e47b42aca5f352e99674090b0fb88082d9a01252b1
3
+ metadata.gz: 845f824374bd07e832f915da01a2c4f0139ceab3836b121397d66f710c83a789
4
+ data.tar.gz: 8eeb1c1abc669c85333bc201875b8e07a5af34803dcae9753875ee12b288895b
5
5
  SHA512:
6
- metadata.gz: bd4167df611518483ef247a86cf557a094a33b203f61bdbcb3796afaf255060c48706aaf50f74809a74b4190d2614e10cf604a764f28de31b7978d8b28db7945
7
- data.tar.gz: 245b629a1c2729a7e43d09a47c9e5833e3032699ca4d2b80479d19b9dfc44f4d14eb16261d2c0a113794ffea3e1eff029aa9cb1ed314e9e6f887c5fa16de28d9
6
+ metadata.gz: 1a7ee52afb255c6da0cee58bcd53f6639a6994cf68e6138c581dd1729d3e382197f5b1ad83916c100774ac6e721ad0f2f88e7c9c6e3419396cdaa7b7252fb8e1
7
+ data.tar.gz: f3bbff63007f3857f556908b553f5fa20a5c7a3da7934f478f1da0a7c967864dd82e597c3388a2ff78a0c2cd647c29d970689b60ebd130af275029431f23c52b
@@ -25,8 +25,20 @@ module GD
25
25
  # @return [Array<GD::GIS::Feature>]
26
26
  # @raise [JSON::ParserError] if the file is invalid JSON
27
27
  # @raise [Errno::ENOENT] if the file does not exist
28
- def self.load(path)
29
- data = JSON.parse(File.read(path))
28
+ def self.load(source)
29
+
30
+ geojson = case source
31
+ when String
32
+ if source.strip.start_with?("{", "[")
33
+ JSON.parse(source)
34
+ else
35
+ JSON.parse(File.read(source))
36
+ end
37
+ when Hash
38
+ source
39
+ else
40
+ raise ArgumentError, "Unsupported GeoJSON source"
41
+ end
30
42
 
31
43
  # 1) Detect CRS
32
44
  crs_name = data["crs"]&.dig("properties", "name")
data/lib/gd/gis/map.rb CHANGED
@@ -334,9 +334,9 @@ module GD
334
334
  #
335
335
  # @param path [String] path to GeoJSON file
336
336
  # @return [void]
337
- def add_geojson(path)
337
+ def add_geojson(source)
338
338
  @style ||= GD::GIS::Style.default
339
- features = LayerGeoJSON.load(path)
339
+ features = LayerGeoJSON.load(source)
340
340
 
341
341
  features.each do |feature|
342
342
  maybe_create_line_label(feature)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libgd-gis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Germán Alberto Giménez Silva