zone_detect 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,92 @@
1
+ /*
2
+ * Copyright (c) 2018, Bertold Van den Bergh (vandenbergh@bertold.org)
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright
8
+ * notice, this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright
10
+ * notice, this list of conditions and the following disclaimer in the
11
+ * documentation and/or other materials provided with the distribution.
12
+ * * Neither the name of the author nor the
13
+ * names of its contributors may be used to endorse or promote products
14
+ * derived from this software without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR DISTRIBUTOR BE LIABLE FOR ANY
20
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ #include <stdint.h>
29
+
30
+ #ifndef INCL_ZONEDETECT_H_
31
+ #define INCL_ZONEDETECT_H_
32
+
33
+ #if !defined(ZD_EXPORT)
34
+ #if defined(_MSC_VER)
35
+ #define ZD_EXPORT __declspec(dllimport)
36
+ #else
37
+ #define ZD_EXPORT
38
+ #endif
39
+ #endif
40
+
41
+ typedef enum {
42
+ ZD_LOOKUP_IGNORE = -3,
43
+ ZD_LOOKUP_END = -2,
44
+ ZD_LOOKUP_PARSE_ERROR = -1,
45
+ ZD_LOOKUP_NOT_IN_ZONE = 0,
46
+ ZD_LOOKUP_IN_ZONE = 1,
47
+ ZD_LOOKUP_IN_EXCLUDED_ZONE = 2,
48
+ ZD_LOOKUP_ON_BORDER_VERTEX = 3,
49
+ ZD_LOOKUP_ON_BORDER_SEGMENT = 4
50
+ } ZDLookupResult;
51
+
52
+ typedef struct {
53
+ ZDLookupResult lookupResult;
54
+
55
+ uint32_t polygonId;
56
+ uint32_t metaId;
57
+ uint8_t numFields;
58
+ char **fieldNames;
59
+ char **data;
60
+ } ZoneDetectResult;
61
+
62
+ struct ZoneDetectOpaque;
63
+ typedef struct ZoneDetectOpaque ZoneDetect;
64
+
65
+ #ifdef __cplusplus
66
+ extern "C" {
67
+ #endif
68
+
69
+ ZD_EXPORT ZoneDetect *ZDOpenDatabase(const char *path);
70
+ ZD_EXPORT ZoneDetect *ZDOpenDatabaseFromMemory(void* buffer, size_t length);
71
+ ZD_EXPORT void ZDCloseDatabase(ZoneDetect *library);
72
+
73
+ ZD_EXPORT ZoneDetectResult *ZDLookup(const ZoneDetect *library, float lat, float lon, float *safezone);
74
+ ZD_EXPORT void ZDFreeResults(ZoneDetectResult *results);
75
+
76
+ ZD_EXPORT const char *ZDGetNotice(const ZoneDetect *library);
77
+ ZD_EXPORT uint8_t ZDGetTableType(const ZoneDetect *library);
78
+ ZD_EXPORT const char *ZDLookupResultToString(ZDLookupResult result);
79
+
80
+ ZD_EXPORT int ZDSetErrorHandler(void (*handler)(int, int));
81
+ ZD_EXPORT const char *ZDGetErrorString(int errZD);
82
+
83
+ ZD_EXPORT float* ZDPolygonToList(const ZoneDetect *library, uint32_t polygonId, size_t* length);
84
+
85
+ ZD_EXPORT char* ZDHelperSimpleLookupString(const ZoneDetect* library, float lat, float lon);
86
+ ZD_EXPORT void ZDHelperSimpleLookupStringFree(char* str);
87
+
88
+ #ifdef __cplusplus
89
+ }
90
+ #endif
91
+
92
+ #endif // INCL_ZONEDETECT_H_
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+
5
+ $VPATH << '$(srcdir)/contrib/ZoneDetect/library' # rubocop:disable Style/GlobalVars
6
+ $srcs = ['zone_detect.c', 'contrib/ZoneDetect/library/zonedetect.c'] # rubocop:disable Style/GlobalVars
7
+
8
+ append_cppflags '-I$(srcdir)/contrib/ZoneDetect/library'
9
+ create_makefile 'zone_detect/zone_detect'
@@ -0,0 +1,49 @@
1
+ #include "zone_detect.h"
2
+
3
+ struct zd_data {
4
+ ZoneDetect *cd;
5
+ };
6
+
7
+ static VALUE initialize(VALUE self, VALUE path);
8
+ static VALUE find(VALUE self, VALUE lat, VALUE lng);
9
+ static VALUE zd_alloc(VALUE klass);
10
+ static void zd_free(void *data);
11
+
12
+ static const rb_data_type_t zd_type = {
13
+ "zonedetect",
14
+ {0, zd_free, 0,},
15
+ 0, 0,
16
+ RUBY_TYPED_FREE_IMMEDIATELY
17
+ };
18
+
19
+ static void zd_free(void *data) {
20
+ ZDCloseDatabase(((struct zd_data *)data)->cd);
21
+ }
22
+
23
+ static VALUE zd_alloc(VALUE klass) {
24
+ struct zd_data *d;
25
+ return TypedData_Make_Struct(klass, struct zd_data, &zd_type, d);
26
+ }
27
+
28
+ void Init_zone_detect(void) {
29
+ VALUE ZoneDetect = rb_define_class("ZoneDetect", rb_cObject);
30
+ rb_define_alloc_func(ZoneDetect, zd_alloc);
31
+ rb_define_method(ZoneDetect, "initialize", initialize, 1);
32
+ rb_define_method(ZoneDetect, "find", find, 2);
33
+ }
34
+
35
+ static VALUE initialize(VALUE self, VALUE path) {
36
+ struct zd_data *d;
37
+ TypedData_Get_Struct(self, struct zd_data, &zd_type, d);
38
+ d->cd = ZDOpenDatabase(StringValuePtr(path));
39
+ return self;
40
+ }
41
+
42
+ static VALUE find(VALUE self, VALUE lat, VALUE lng) {
43
+ struct zd_data *d;
44
+ TypedData_Get_Struct(self, struct zd_data, &zd_type, d);
45
+ char *simple = ZDHelperSimpleLookupString(d->cd, NUM2DBL(lat), NUM2DBL(lng));
46
+ VALUE str = rb_str_new(simple, strlen(simple));
47
+ free(simple);
48
+ return str;
49
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef ZONE_DETECT_H
2
+ #define ZONE_DETECT_H 1
3
+
4
+ #include "ruby.h"
5
+
6
+ #include "contrib/ZoneDetect/library/zonedetect.h"
7
+
8
+ #endif /* ZONE_DETECT_H */
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ZoneDetect
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'zone_detect/zone_detect'
4
+ require_relative 'zone_detect/version'
@@ -0,0 +1,7 @@
1
+ class ZoneDetect
2
+ VERSION: String
3
+
4
+ def initialize: (path: String) -> void
5
+
6
+ def find: (lat: Numeric, lng: Numeric) -> String
7
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/zone_detect/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'zone_detect'
7
+ spec.version = ZoneDetect::VERSION
8
+ spec.authors = ['Alexander Cederblad']
9
+ spec.email = ['alexcederblad@gmail.com']
10
+
11
+ spec.summary = 'Find time zone from given coordinates'
12
+ spec.homepage = 'https://github.com/fishbrain/zone_detect'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = '>= 2.6.0'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
+ spec.metadata['rubygems_mfa_required'] = 'true'
19
+
20
+ spec.files = Dir[
21
+ 'LICENSE',
22
+ 'Gemfile',
23
+ 'README.markdown',
24
+ 'CHANGELOG.markdown',
25
+ 'zone_detect.gemspec',
26
+ 'ext/*/*.{rb,c,h}',
27
+ 'ext/*/contrib/ZoneDetect/LICENSE',
28
+ 'ext/*/contrib/ZoneDetect/library/*.{c,h}',
29
+ 'lib/**/*.rb',
30
+ 'sig/**/*',
31
+ ]
32
+ spec.require_paths = ['lib']
33
+ spec.extensions = ['ext/zone_detect/extconf.rb']
34
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zone_detect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Cederblad
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - alexcederblad@gmail.com
16
+ executables: []
17
+ extensions:
18
+ - ext/zone_detect/extconf.rb
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.markdown
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.markdown
25
+ - ext/zone_detect/contrib/ZoneDetect/LICENSE
26
+ - ext/zone_detect/contrib/ZoneDetect/library/zonedetect.c
27
+ - ext/zone_detect/contrib/ZoneDetect/library/zonedetect.h
28
+ - ext/zone_detect/extconf.rb
29
+ - ext/zone_detect/zone_detect.c
30
+ - ext/zone_detect/zone_detect.h
31
+ - lib/zone_detect.rb
32
+ - lib/zone_detect/version.rb
33
+ - sig/zone_detect.rbs
34
+ - zone_detect.gemspec
35
+ homepage: https://github.com/fishbrain/zone_detect
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://github.com/fishbrain/zone_detect
40
+ source_code_uri: https://github.com/fishbrain/zone_detect
41
+ rubygems_mfa_required: 'true'
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.6.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.3.0.dev
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Find time zone from given coordinates
61
+ test_files: []