ipparse 0.1.0 → 0.1.1
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/ipparse.gemspec +2 -2
- data/lib/ipparse.rb +4 -3
- data/lib/version.rb +1 -1
- data/test/test_ipparse.rb +1 -0
- metadata +2 -2
data/ipparse.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ipparse}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Zhang Jinzhu"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-09-16}
|
10
10
|
s.default_executable = %q{ipparse}
|
11
11
|
s.description = %q{IP Parse}
|
12
12
|
s.email = %q{wosmvp@gmail.com}
|
data/lib/ipparse.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$KCODE = 'UTF8' if RUBY_VERSION < '1.9'
|
2
3
|
# IPV4
|
3
4
|
class IPParse
|
4
5
|
@@data ||= []
|
@@ -7,7 +8,7 @@ class IPParse
|
|
7
8
|
return false unless ip.to_s =~ /(\d+\.){3}\d+/
|
8
9
|
ip = ip.scan(/\d+/).map{|x| x.rjust(3, '0')}.join('.')
|
9
10
|
|
10
|
-
return dichotomizing(@@data[ip[0,3].to_i] ||= file_to_a("#{File.dirname(__FILE__)}/../data/#{ip[0,3].to_i}.txt"),ip) ||
|
11
|
+
return dichotomizing(@@data[ip[0,3].to_i] ||= file_to_a("#{File.dirname(__FILE__)}/../data/#{ip[0,3].to_i}.txt"),ip) ||dichotomizing(@@data[0] ||= file_to_a("#{File.dirname(__FILE__)}/../data/0.txt"),ip) || "Unknown"
|
11
12
|
end
|
12
13
|
|
13
14
|
protected
|
@@ -16,7 +17,7 @@ class IPParse
|
|
16
17
|
cur = arg[cen]
|
17
18
|
|
18
19
|
# arg.size = 0 || 1
|
19
|
-
return
|
20
|
+
return cur && cur[0,15] <= ip && cur[16,15] >= ip ? cur[32...-1] : false if cen == 0
|
20
21
|
return dichotomizing(arg[0...cen],ip) if cur[0,15] > ip
|
21
22
|
return dichotomizing(arg[cen+1..-1],ip) if cur[16,15] < ip
|
22
23
|
return arg[cen][32...-1]
|
data/lib/version.rb
CHANGED
data/test/test_ipparse.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ipparse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zhang Jinzhu
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-16 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|