ipparse 0.0.1 → 0.0.2

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 CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ipparse}
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
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-02-17}
9
+ s.date = %q{2009-02-18}
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
@@ -22,13 +22,16 @@ class IPParse
22
22
 
23
23
  protected
24
24
  def self.dichotomizing(arg,ip)
25
- cen = (arg.length/2).to_i
26
- x = arg[cen].split(/\s+/,3)
25
+ size = arg.size
26
+ cen = size/2
27
27
 
28
- return (x[0]..x[1]).include?(ip) ? x[2] : false if arg.size == 1
29
- return dichotomizing(arg[0...cen],ip) if x[0] > ip
30
- return dichotomizing(arg[cen...arg.length],ip) if x[1] < ip
31
- return x[2]
28
+ # '001.053.000.000 001.153.255.255 IANA' < '001.053.000.000' + '1'
29
+ # reduce 'string'.split call
30
+ return dichotomizing(arg[0...cen],ip) if size != 1 && (arg[cen] > ip + '1')
31
+ x = arg[cen].split(/\s+/,3)
32
+ return (x[0]..x[1]).include?(ip) ? x[2] : false if size == 1
33
+ return dichotomizing(arg[cen...size],ip) if x[1] < ip
34
+ return x[2]
32
35
  end
33
36
 
34
37
  def self.format(ip)
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module IPParse
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/test/test_ipparse.rb CHANGED
@@ -4,8 +4,18 @@ require 'test/unit'
4
4
  class TestIPParse < Test::Unit::TestCase
5
5
  def test_parse
6
6
  assert_equal IPParse.parse('222.153.3'),false
7
- assert_equal IPParse.parse('222.15.153.3'),"江西省云南市"
8
- assert_equal IPParse.parse('24.38.192.2'),"美国"
7
+ ips = {
8
+ "178.61.84.32 " => "Unknown",
9
+ "218.58.88.175" => "山东省青岛市开发区",
10
+ "212.1.1.1 " => "意大利",
11
+ "192.245.148.0" => "阿尔及利亚",
12
+ "116.254.254.0" => "广东省广州市",
13
+ "116.254.254.0" => "广东省广州市",
14
+ "16.34.110.150" => "美国",
15
+ "222.15.153.3" => "江西省云南市",
16
+ "24.38.192.2" => "美国"
17
+ }
18
+ ips.map {|k,v| assert_equal IPParse.parse(k),v}
9
19
  end
10
20
 
11
21
  def test_format
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.0.1
4
+ version: 0.0.2
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-02-17 00:00:00 +08:00
12
+ date: 2009-02-18 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15