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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2843375b1e8d8c3774555b89c6a013a1a3c72e6
4
- data.tar.gz: 451511841770b5b769eaa81cfce5e69c3d0cbc7d
3
+ metadata.gz: 51894aa7d843175da120f97cd8bd4620b0f4989e
4
+ data.tar.gz: bd66c0b0f995b967dae4ce8745de0b114a659819
5
5
  SHA512:
6
- metadata.gz: 877f77cb9f8d8fe03e4d811728a4d5d974ca379055d704e5c6395aaf85fcd2a9b0a7a66d9022de69bd8ddf261ea0d52ac8b58b49e93e793d6b6152f91f9e6846
7
- data.tar.gz: b5dce2b00f9cc63b43cf0e7b59b28c2090e0e38691145f267ab988191d680c63c30a3e51447340b252c959b6b695c601f7ae2a14989c5cb43205a1c0f3430dfc
6
+ metadata.gz: 36ce4628c8d63a91d529ebea2e9782daedb965d4f9c4cb2760c15362970ddd367e20af97e59bee97ad92fe7051de5f693df93b2588df4dcbbe89b6a8fa98731a
7
+ data.tar.gz: a11d9901788adb08187d903fae7e94c698c1e63bf9f5c89352a0f8c083b990a97bf4529f63a7ae9e0f654f107cb5478191584b42544dbafee92b096730d58759
@@ -1,3 +1,3 @@
1
1
  module ChinaAdIp
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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 $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]] }
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 $locations.nil?
76
- $locations = CSV.read(path,:encoding=>"utf-8")
77
- $locations = Hash[$locations.map {|location| id = location.shift; [id,location << !!id.match(/^1156/)] }]
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 $ip_sections && $locations
87
+ if @ip_sections && @locations
88
88
  index = ChinaAdIp.binarysearch(self.arr_pointer,ip_addr.to_i,ip_arr.length)
89
- $locations[$ip_sections[index][2]]
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
- @@ip_arr ||= $ip_sections.collect{|ip_section| ip_section[0]}.to_a
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: china_ad_ip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - suezhen