china_ad_ip 0.1.5 → 0.1.6
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/README.md +1 -0
- data/lib/china_ad_ip/version.rb +1 -1
- data/lib/china_ad_ip.rb +10 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a244dc776c275d808565a05f45e8ef3df31093c
|
4
|
+
data.tar.gz: 3a882d4bc95435917038b4785197613fba222fab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd3d64a95e9c0b3f28b54f4b2696a9b9d7b96c664a1234516a5926ef588cd7934129060613304934ed37ab100fcb28c18e2990f691aba0e6a94c54b208d78643
|
7
|
+
data.tar.gz: eb18e99aec59bd2f85c1faa57854dd1f1fd8ef6a628dde7d5fac339ace4e88cb1bf0db8c9ab540059f656423af924bc57408420ff64022337bff140d272bb001
|
data/README.md
CHANGED
data/lib/china_ad_ip/version.rb
CHANGED
data/lib/china_ad_ip.rb
CHANGED
@@ -63,7 +63,11 @@ module ChinaAdIp
|
|
63
63
|
if @ip_sections.nil?
|
64
64
|
@ip_sections = CSV.read(path)
|
65
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
|
+
ip_arr
|
67
|
+
ip_arr_length
|
68
|
+
arr_pointer
|
66
69
|
end
|
70
|
+
true
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
@@ -73,9 +77,10 @@ module ChinaAdIp
|
|
73
77
|
raise(::ArgumentError, "not exists: #{path}")
|
74
78
|
else
|
75
79
|
if @locations.nil?
|
76
|
-
@locations = CSV.read(path)
|
80
|
+
@locations = CSV.read(path,:encoding=>"utf-8")
|
77
81
|
@locations = Hash[@locations.map {|location| id = location.shift; [id,location << !!id.match(/^1156/)] }]
|
78
82
|
end
|
83
|
+
true
|
79
84
|
end
|
80
85
|
end
|
81
86
|
|
@@ -85,7 +90,7 @@ module ChinaAdIp
|
|
85
90
|
ip_addr = ChinaAdIp::IPv4.new(addr)
|
86
91
|
|
87
92
|
if @ip_sections && @locations
|
88
|
-
index = ChinaAdIp.binarysearch(self.arr_pointer,ip_addr.to_i,
|
93
|
+
index = ChinaAdIp.binarysearch(self.arr_pointer,ip_addr.to_i,ip_arr_length)
|
89
94
|
@locations[@ip_sections[index][2]]
|
90
95
|
else
|
91
96
|
raise(::ArgumentError, "not exists csv data")
|
@@ -93,6 +98,9 @@ module ChinaAdIp
|
|
93
98
|
|
94
99
|
end
|
95
100
|
|
101
|
+
def self.ip_arr_length
|
102
|
+
@ip_arr_length ||= ip_arr.length
|
103
|
+
end
|
96
104
|
|
97
105
|
def self.ip_arr
|
98
106
|
@ip_arr ||= @ip_sections.collect{|ip_section| ip_section[0]}.to_a
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: china_ad_ip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- suezhen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|