zone_detect 0.1.0 → 0.2.0

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: f74a81499efffb49b63519c5206da7a679fa04810586fa1d3af612696d91ab72
4
- data.tar.gz: b6be4177fcb50c5b88fa4f3c7a8586950e3be4e269ba2e955ac64ace722770d7
3
+ metadata.gz: 5c5fa51707db0e4ded3e1fa680b3354e22deccd868a3b953190918979cce32b3
4
+ data.tar.gz: 12ae78865eb600807b27855e6cc4fddefe2e3fbe5d19c61b4a95ca49cdf84f39
5
5
  SHA512:
6
- metadata.gz: 4bfc7dd6883badcfcd138a821b267da5b437899c4a7276ab74cc18c45a524b56e953f5aa1539ce297c5a27a0f285317cd0a7dffe20910a54244d38800b6052d4
7
- data.tar.gz: 132fb305d66ed4129b5c51fb0f4f44bc80dff950d72c7ad31c7f346f08cf2acffd066c51391591c92daac81b1eff29440133e8b1255a7917669ebb4fde6f4c04
6
+ metadata.gz: e602ee96fe1f093410bf66bd9313416545c366e4f0659ce4b612346ed4178203ae47e87169c033bee78a9328aaeae7cbbac30b645eb0a036a539d044fa431851
7
+ data.tar.gz: 0b749e0ced9a56dac993771d43e681e5cf2872e12cc049560699b91850b689e48d5b868a3abcda13590d2ea67e4149f60572b5733aaa32df7df355e028a487e1
data/CHANGELOG.markdown CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2023-01-20
4
+
5
+ ### Added
6
+
7
+ - Add raise error when unable to read data file
8
+ - Add class method API
9
+
3
10
  ## [0.1.0] - 2023-01-18
4
11
 
5
12
  - Initial release
data/README.markdown CHANGED
@@ -24,9 +24,17 @@ $ gem install zone_detect
24
24
 
25
25
  ```ruby
26
26
  require "zone_detect"
27
- zd = ZoneDetect.new
27
+
28
+ zd = ZoneDetect.new('/path/to/data.bin')
28
29
  zd.find(59.329, 18.063)
29
30
  # => "Europe/Stockholm"
31
+
32
+ # Alternative usage:
33
+ ZoneDetect.configure do |config|
34
+ config.timezone_data_path = '/path/to/data.bin'
35
+ end
36
+ ZoneDetect.find(59.334, 18.063)
37
+ # => "Europe/Stockholm"
30
38
  ```
31
39
 
32
40
  ## Development
@@ -25,6 +25,7 @@
25
25
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
  */
27
27
 
28
+ #include <stddef.h>
28
29
  #include <stdint.h>
29
30
 
30
31
  #ifndef INCL_ZONEDETECT_H_
@@ -36,6 +36,8 @@ static VALUE initialize(VALUE self, VALUE path) {
36
36
  struct zd_data *d;
37
37
  TypedData_Get_Struct(self, struct zd_data, &zd_type, d);
38
38
  d->cd = ZDOpenDatabase(StringValuePtr(path));
39
+ if (!d->cd)
40
+ rb_raise(rb_eRuntimeError, "Could not open data file");
39
41
  return self;
40
42
  }
41
43
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ZoneDetect
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/zone_detect.rb CHANGED
@@ -2,3 +2,26 @@
2
2
 
3
3
  require_relative 'zone_detect/zone_detect'
4
4
  require_relative 'zone_detect/version'
5
+
6
+ # :nodoc:
7
+ class ZoneDetect
8
+ # :nodoc:
9
+ class Config
10
+ attr_accessor :timezone_data_path
11
+ end
12
+
13
+ def self.configure
14
+ config = Config.new
15
+ yield config
16
+ raise 'Missing required configuration: timezone_data_path' unless config.timezone_data_path
17
+
18
+ @instance = ZoneDetect.new(config.timezone_data_path)
19
+ nil
20
+ end
21
+
22
+ def self.find(lat, lng)
23
+ raise 'Missing configuration' unless @instance
24
+
25
+ @instance.find(lat, lng)
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zone_detect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Cederblad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-19 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  requirements: []
57
- rubygems_version: 3.3.0.dev
57
+ rubygems_version: 3.3.12
58
58
  signing_key:
59
59
  specification_version: 4
60
60
  summary: Find time zone from given coordinates