ip3country 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/country_lookup.rb +29 -10
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78b3536e8481cda95c23ab45a43612308c4d6cbaa5e3c61050e46dcc079b52f1
|
4
|
+
data.tar.gz: 62214a88c865ff87166874df6f9fa9503eaa0e45122d2d4a85fa48de94a78af2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1d3e2550e4d2b70f36e439ba135ac727560aaccb1cd3c8c93bc138409b9302f6518d0d164b6f278ee110869f1a57826a70fa4cfab78a13dd5bfe1404cee78ca
|
7
|
+
data.tar.gz: 5e68609330b91025d3bc8b3fa018fa92a0f80036d3388f7132fd4facefe0d9ccfee1e3e26ba1efe1858ca0086424d5391e30593494298b8e231cb7896fc62769
|
data/lib/country_lookup.rb
CHANGED
@@ -2,6 +2,9 @@ module CountryLookup
|
|
2
2
|
|
3
3
|
class Lookup
|
4
4
|
def initialize
|
5
|
+
@country_codes = Array.new
|
6
|
+
@ip_ranges = Array.new
|
7
|
+
@country_table = Array.new
|
5
8
|
initialize_from_file
|
6
9
|
end
|
7
10
|
|
@@ -23,7 +26,7 @@ module CountryLookup
|
|
23
26
|
end
|
24
27
|
|
25
28
|
def lookup_ip_number(ip_number)
|
26
|
-
index =
|
29
|
+
index = binary_search(ip_number)
|
27
30
|
cc = @country_codes[index]
|
28
31
|
if cc == '--'
|
29
32
|
return nil
|
@@ -55,12 +58,9 @@ module CountryLookup
|
|
55
58
|
# 242.n2.n3.c: if n >= 240 but < 65536. n2 being lower order byte
|
56
59
|
# 243.n2.n3.n4.c: if n >= 65536. n2 being lower order byte
|
57
60
|
def initialize_from_file
|
58
|
-
unless @country_codes.
|
61
|
+
unless @country_codes.length == 0
|
59
62
|
return
|
60
63
|
end
|
61
|
-
@country_codes = Array.new
|
62
|
-
@ip_ranges = Array.new
|
63
|
-
@country_table = Array.new
|
64
64
|
|
65
65
|
File.open(File.dirname(__FILE__) + '/ip_supalite.table') do |file|
|
66
66
|
until file.eof?
|
@@ -99,22 +99,41 @@ module CountryLookup
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def self.initialize
|
102
|
-
|
102
|
+
if !@initialize_bg_thread.nil? && @initialize_bg_thread.alive?
|
103
|
+
@initialize_bg_thread.join
|
104
|
+
else
|
105
|
+
@lookup = Lookup.new
|
106
|
+
end
|
103
107
|
return nil
|
104
108
|
end
|
105
109
|
|
110
|
+
def self.initialize_async
|
111
|
+
if !@initialize_bg_thread.nil? && @initialize_bg_thread.alive?
|
112
|
+
return @initialize_bg_thread
|
113
|
+
end
|
114
|
+
@initialize_bg_thread = Thread.new { @lookup = Lookup.new }
|
115
|
+
return @initialize_bg_thread
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.is_ready_for_lookup
|
119
|
+
!@lookup.nil?
|
120
|
+
end
|
121
|
+
|
106
122
|
def self.lookup_ip_string(ip_string)
|
107
|
-
if
|
108
|
-
|
123
|
+
if !is_ready_for_lookup
|
124
|
+
initialize
|
109
125
|
end
|
110
126
|
@lookup.lookup_ip_string(ip_string)
|
111
127
|
end
|
112
128
|
|
113
129
|
def self.lookup_ip_number(ip_number)
|
114
|
-
if
|
115
|
-
|
130
|
+
if !is_ready_for_lookup
|
131
|
+
initialize
|
116
132
|
end
|
117
133
|
@lookup.lookup_ip_number(ip_number)
|
118
134
|
end
|
119
135
|
|
136
|
+
def teardown
|
137
|
+
@lookup = nil
|
138
|
+
end
|
120
139
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ip3country
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Statsig, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2023-05-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.14'
|
13
41
|
description: A ruby, zero-dependency, super small version of IP2Location LITE country
|
14
42
|
lookups
|
15
43
|
email: support@statsig.com
|
@@ -38,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
66
|
- !ruby/object:Gem::Version
|
39
67
|
version: '0'
|
40
68
|
requirements: []
|
41
|
-
rubygems_version: 3.
|
69
|
+
rubygems_version: 3.3.7
|
42
70
|
signing_key:
|
43
71
|
specification_version: 4
|
44
72
|
summary: ip3country for ruby
|