china_ad_ip 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9bc78627bbd6e04faac3df9f93c7b18ea6f5582
4
- data.tar.gz: 02be7d286c72a6478df85af793a5011c529f3a42
3
+ metadata.gz: 5a244dc776c275d808565a05f45e8ef3df31093c
4
+ data.tar.gz: 3a882d4bc95435917038b4785197613fba222fab
5
5
  SHA512:
6
- metadata.gz: 6c994bfd73e03f14b7ea4f75c4a87c61fc1432553cb7ce8e1f0248c017284f37fa1869fb4d5a8d65d8561552ae4269f6a2129dbca30fd2859d085696c5ece70e
7
- data.tar.gz: c1300750e77897772acfa2e91c98c18adf820a862970657f2be5a8c334c172f99e91b8e016653180114b4bab948745f9e1964b10cb5b6f10d7a0e93fffc70a33
6
+ metadata.gz: bd3d64a95e9c0b3f28b54f4b2696a9b9d7b96c664a1234516a5926ef588cd7934129060613304934ed37ab100fcb28c18e2990f691aba0e6a94c54b208d78643
7
+ data.tar.gz: eb18e99aec59bd2f85c1faa57854dd1f1fd8ef6a628dde7d5fac339ace4e88cb1bf0db8c9ab540059f656423af924bc57408420ff64022337bff140d272bb001
data/README.md CHANGED
@@ -6,6 +6,7 @@ TODO: Write a gem description
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
+ gem 'ffi'
9
10
  gem 'china_ad_ip'
10
11
 
11
12
  And then execute:
@@ -1,3 +1,3 @@
1
1
  module ChinaAdIp
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
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,ip_arr.length)
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.5
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 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler