place_kit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PlaceKit
4
+ VERSION = File.read(File.expand_path('../../VERSION', __dir__)).strip.freeze
5
+ end
data/lib/place_kit.rb ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/all'
4
+ require 'csv'
5
+ require 'fastcsv'
6
+
7
+ module PlaceKit
8
+ DB = File.join(__dir__, 'db', 'GeoLite2-City-Locations-en.csv')
9
+
10
+ @cache = {}
11
+
12
+ # Look up time zone.
13
+ #
14
+ # @param [String|Symbol] country Country ISO code.
15
+ # @param [String|Symbol] region Region ISO (subdivison 1) code.
16
+ # @param [String|Symbol] city City name.
17
+ def self.lookup(country, region, city)
18
+ country = country.to_s.humanize.downcase
19
+ region = region.to_s.humanize.downcase
20
+ city = city.to_s.humanize.downcase
21
+
22
+ val = @cache.dig(country, region, city)
23
+ return val if val
24
+
25
+ @cache[country] ||= {}
26
+ @cache[country][region] ||= {}
27
+
28
+ File.open(DB) do |f|
29
+ FastCSV.raw_parse(f) do |entry|
30
+ next unless entry[4]&.downcase == country &&
31
+ entry[6]&.downcase == region &&
32
+ entry[10]&.downcase == city
33
+
34
+ time_zone = ActiveSupport::TimeZone.new(entry[12])
35
+
36
+ @cache[country][region][city] = time_zone
37
+
38
+ return time_zone
39
+ end
40
+ end
41
+
42
+ @cache[country][region][city] = nil
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: place_kit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Third Party Transportation Systems LLC
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 6.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: fastcsv
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.0.6
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.0.6
47
+ - !ruby/object:Gem::Dependency
48
+ name: rubocop-next
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.0.0
61
+ description: "Time zone lookup by country, region, and city for those times when latitude/longitude
62
+ coordinates just aren’tavailable \U0001F680"
63
+ email: hello@next-tms.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - lib/db/GeoLite2-City-Locations-en.csv
69
+ - lib/place_kit.rb
70
+ - lib/place_kit/version.rb
71
+ homepage: https://github.com/next-tms/place_kit
72
+ licenses: []
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.2.0
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.4.10
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: "Time zone lookup by country, region, and city \U0001F680"
93
+ test_files: []