turfjs 0.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/turfjs-build.js +1 -0
  3. data/lib/turfjs.rb +37 -0
  4. metadata +78 -0
data/lib/turfjs.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'execjs'
4
+ require 'active_support/core_ext/string/inflections'
5
+
6
+ module TurfJS
7
+ class Error < StandardError; end
8
+ def self.context
9
+ @context ||=
10
+ begin
11
+ source = File.read(File.expand_path('turfjs-build.js', __dir__))
12
+ ExecJS.compile(source)
13
+ end
14
+ end
15
+
16
+ def self.turf_api_mapping
17
+ @turf_api_mapping ||=
18
+ context.call('turfAPIs').map do |name|
19
+ [name.underscore.to_sym, name]
20
+ end.to_h
21
+ end
22
+
23
+ def self.method_missing(method, *args)
24
+ turf_api_name = turf_api_mapping[method]
25
+ return super unless turf_api_name
26
+
27
+ begin
28
+ context.call("turf.#{method}", *args)
29
+ rescue ExecJS::ProgramError => e
30
+ raise Error, e.message
31
+ end
32
+ end
33
+
34
+ def self.respond_to_missing?(method, include_private = false)
35
+ turf_api_mapping.keys.include?(method) || super
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turfjs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Yin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: execjs
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.2.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: Turf.js is an advanced geospatial analasis library for GeoJSON data.
48
+ email: layerssss@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/turfjs-build.js
54
+ - lib/turfjs.rb
55
+ homepage: https://github.com/layerssss/turfjs-ruby
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.0.3
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Ruby TurfJS is a bridge to JavaScript library Turf.js
78
+ test_files: []