ip2location_ruby 0.1.2 → 0.2.0
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.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/ip2location_ruby.gemspec +3 -3
- data/lib/ip2location_ruby/ip2location_record.rb +5 -3
- data/lib/ip2location_ruby.rb +3 -3
- data/spec/ip2location_ruby_spec.rb +0 -2
- metadata +6 -3
data/Rakefile
CHANGED
|
@@ -14,7 +14,7 @@ require 'rake'
|
|
|
14
14
|
require 'jeweler'
|
|
15
15
|
Jeweler::Tasks.new do |gem|
|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
|
17
|
-
gem.name = "
|
|
17
|
+
gem.name = "ip2location_ruby"
|
|
18
18
|
gem.homepage = "http://github.com/zhu1230/ip2location"
|
|
19
19
|
gem.license = "MIT"
|
|
20
20
|
gem.summary = %Q{the ip2location ruby library}
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.2.0
|
data/ip2location_ruby.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "ip2location_ruby"
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.2.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Vincent.Z"]
|
|
12
|
-
s.date = "2013-05-
|
|
12
|
+
s.date = "2013-05-16"
|
|
13
13
|
s.description = "the ip2location ruby library"
|
|
14
14
|
s.email = "zhu1230@gmail.com"
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
|
27
27
|
"VERSION",
|
|
28
28
|
"ip2location_ruby.gemspec",
|
|
29
29
|
"lib/ip2location_ruby.rb",
|
|
30
|
-
"lib/ip2location_ruby
|
|
30
|
+
"lib/ip2location_ruby/database_config.rb",
|
|
31
31
|
"lib/ip2location_ruby/i2l_float_data.rb",
|
|
32
32
|
"lib/ip2location_ruby/i2l_ip_data.rb",
|
|
33
33
|
"lib/ip2location_ruby/i2l_string_data.rb",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
class Ip2LocationRecord
|
|
1
|
+
class Ip2LocationRecord
|
|
2
2
|
def self.init(database, ip_version)
|
|
3
|
-
|
|
3
|
+
cls = Class.new(BinData::Record)
|
|
4
|
+
cls.class_eval {
|
|
4
5
|
endian :little
|
|
5
6
|
i2l_ip_data :ip_from, :ip_version => ip_version
|
|
6
7
|
|
|
@@ -16,6 +17,7 @@ class Ip2LocationRecord <BinData::Record
|
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
i2l_ip_data :ip_to, :ip_version => ip_version
|
|
19
|
-
}
|
|
20
|
+
}
|
|
21
|
+
cls
|
|
20
22
|
end
|
|
21
23
|
end
|
data/lib/ip2location_ruby.rb
CHANGED
|
@@ -9,7 +9,7 @@ require 'ip2location_ruby/i2l_ip_data'
|
|
|
9
9
|
require 'ip2location_ruby/ip2location_record'
|
|
10
10
|
|
|
11
11
|
class Ip2location
|
|
12
|
-
attr_accessor :v4, :file, :db_index, :count, :base_addr, :ipno, :count, :record, :database, :columns, :ip_version
|
|
12
|
+
attr_accessor :record_class, :v4, :file, :db_index, :count, :base_addr, :ipno, :count, :record, :database, :columns, :ip_version
|
|
13
13
|
|
|
14
14
|
def open(url)
|
|
15
15
|
self.file = File.open(File.expand_path url, 'rb')
|
|
@@ -20,7 +20,7 @@ class Ip2location
|
|
|
20
20
|
self.columns = i2l.databasecolumn + 0
|
|
21
21
|
self.database = DbConfig.setup_database(self.db_index)
|
|
22
22
|
self.ip_version = (i2l.ipversion == 0 ? 4 : 6)
|
|
23
|
-
Ip2LocationRecord.init database, self.ip_version
|
|
23
|
+
self.record_class = (Ip2LocationRecord.init database, self.ip_version)
|
|
24
24
|
self
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -65,7 +65,7 @@ class Ip2location
|
|
|
65
65
|
else
|
|
66
66
|
from_base = ( base_addr + mid * col_length)
|
|
67
67
|
file.seek(from_base)
|
|
68
|
-
return
|
|
68
|
+
return self.record_class.read(file)
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
|
|
@@ -2,11 +2,9 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
|
2
2
|
|
|
3
3
|
describe "Ip2location" do
|
|
4
4
|
it "work correctly with ipv4" do
|
|
5
|
-
|
|
6
5
|
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP-COUNTRY-SAMPLE.bin")
|
|
7
6
|
record = i2l.get_all('13.5.10.6')
|
|
8
7
|
record.should_not be_nil
|
|
9
8
|
record.country_short.should == 'US'
|
|
10
9
|
end
|
|
11
|
-
|
|
12
10
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ip2location_ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-05-
|
|
12
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bindata
|
|
@@ -141,7 +141,7 @@ files:
|
|
|
141
141
|
- VERSION
|
|
142
142
|
- ip2location_ruby.gemspec
|
|
143
143
|
- lib/ip2location_ruby.rb
|
|
144
|
-
- lib/ip2location_ruby
|
|
144
|
+
- lib/ip2location_ruby/database_config.rb
|
|
145
145
|
- lib/ip2location_ruby/i2l_float_data.rb
|
|
146
146
|
- lib/ip2location_ruby/i2l_ip_data.rb
|
|
147
147
|
- lib/ip2location_ruby/i2l_string_data.rb
|
|
@@ -163,6 +163,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
163
163
|
- - ! '>='
|
|
164
164
|
- !ruby/object:Gem::Version
|
|
165
165
|
version: '0'
|
|
166
|
+
segments:
|
|
167
|
+
- 0
|
|
168
|
+
hash: -1108149545426494590
|
|
166
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
170
|
none: false
|
|
168
171
|
requirements:
|