china_ad_ip 0.1.3 → 0.1.4
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 +4 -4
- data/lib/china_ad_ip/version.rb +1 -1
- data/lib/china_ad_ip.rb +10 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51894aa7d843175da120f97cd8bd4620b0f4989e
|
4
|
+
data.tar.gz: bd66c0b0f995b967dae4ce8745de0b114a659819
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36ce4628c8d63a91d529ebea2e9782daedb965d4f9c4cb2760c15362970ddd367e20af97e59bee97ad92fe7051de5f693df93b2588df4dcbbe89b6a8fa98731a
|
7
|
+
data.tar.gz: a11d9901788adb08187d903fae7e94c698c1e63bf9f5c89352a0f8c083b990a97bf4529f63a7ae9e0f654f107cb5478191584b42544dbafee92b096730d58759
|
data/lib/china_ad_ip/version.rb
CHANGED
data/lib/china_ad_ip.rb
CHANGED
@@ -60,9 +60,9 @@ module ChinaAdIp
|
|
60
60
|
unless FileTest::exist?(path)
|
61
61
|
raise(::ArgumentError, "not exists: #{path}")
|
62
62
|
else
|
63
|
-
if
|
64
|
-
|
65
|
-
|
63
|
+
if @ip_sections.nil?
|
64
|
+
@ip_sections = CSV.read(path)
|
65
|
+
@ip_sections.reject!{|ip_section| ChinaAdIp::IPv4.new(ip_section[0]).to_i==0 }.map! { |ip_section| [ChinaAdIp::IPv4.new(ip_section[0]).to_i,ChinaAdIp::IPv4.new(ip_section[1]).to_i,ip_section[2],ip_section[3]] }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -72,9 +72,9 @@ module ChinaAdIp
|
|
72
72
|
unless FileTest::exist?(path)
|
73
73
|
raise(::ArgumentError, "not exists: #{path}")
|
74
74
|
else
|
75
|
-
if
|
76
|
-
|
77
|
-
|
75
|
+
if @locations.nil?
|
76
|
+
@locations = CSV.read(path,:encoding=>"utf-8")
|
77
|
+
@locations = Hash[@locations.map {|location| id = location.shift; [id,location << !!id.match(/^1156/)] }]
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
@@ -84,9 +84,9 @@ module ChinaAdIp
|
|
84
84
|
|
85
85
|
ip_addr = ChinaAdIp::IPv4.new(addr)
|
86
86
|
|
87
|
-
if
|
87
|
+
if @ip_sections && @locations
|
88
88
|
index = ChinaAdIp.binarysearch(self.arr_pointer,ip_addr.to_i,ip_arr.length)
|
89
|
-
|
89
|
+
@locations[@ip_sections[index][2]]
|
90
90
|
else
|
91
91
|
raise(::ArgumentError, "not exists csv data")
|
92
92
|
end
|
@@ -95,12 +95,12 @@ module ChinaAdIp
|
|
95
95
|
|
96
96
|
|
97
97
|
def self.ip_arr
|
98
|
-
|
98
|
+
@ip_arr ||= @ip_sections.collect{|ip_section| ip_section[0]}.to_a
|
99
99
|
end
|
100
100
|
|
101
101
|
def self.arr_pointer
|
102
102
|
buffer = LibC.malloc(ip_arr.first.size * ip_arr.size)
|
103
|
-
buffer.write_array_of_long ip_arr
|
103
|
+
@pointer ||= buffer.write_array_of_long ip_arr
|
104
104
|
end
|
105
105
|
|
106
106
|
end
|