ipcat 1.0.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  A ruby port of the [ipcat](https://github.com/client9/ipcat) library to classify IP addresses from known datacenters
4
4
 
5
+ [![Build Status](https://travis-ci.org/kickstarter/ipcat-ruby.png?branch=master)](https://travis-ci.org/kickstarter/ipcat-ruby)
6
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/kickstarter/ipcat-ruby)
7
+
5
8
  ## Installation
6
9
 
7
10
  With bundler:
@@ -26,3 +29,8 @@ For example,
26
29
 
27
30
  IPCat.datacenter?('127.0.0.1') # => nil
28
31
 
32
+ ## License
33
+
34
+ Copyright (c) 2013 Kickstarter, Inc
35
+
36
+ Released under an [MIT License](http://opensource.org/licenses/MIT)
data/Rakefile CHANGED
@@ -2,12 +2,15 @@ require "rubygems"
2
2
  require "bundler/setup"
3
3
  require 'rake/testtask'
4
4
 
5
+ $:.unshift './lib'
6
+ require 'ipcat'
5
7
  Rake::TestTask.new do |t|
6
- t.pattern = "spec/*_spec.rb"
8
+ t.pattern = "spec/*_spec.rb"
7
9
  end
8
10
 
9
11
  task :default => :test
10
12
 
13
+ desc 'Regenerate data/datacenters'
11
14
  task :generate_dataset do
12
15
 
13
16
  $:.unshift './lib'
@@ -15,3 +18,17 @@ task :generate_dataset do
15
18
  IPCat.load_csv!
16
19
  File.open("data/datacenters", 'w') {|f| f << Marshal.dump(IPCat.ranges) }
17
20
  end
21
+
22
+ desc "Run benchmark"
23
+ task :bench do
24
+
25
+ require 'benchmark'
26
+ # random ips
27
+ ips = 100_000.times.map{ rand(2**32) }
28
+ Benchmark.bm do |x|
29
+ x.report("IPCat.bsearch (100k)") {
30
+ ips.each { |ip| IPCat.bsearch(ip) }
31
+ }
32
+
33
+ end
34
+ end
Binary file
@@ -12,7 +12,7 @@ class IPCat
12
12
  def datacenter?(ip)
13
13
  bsearch(ip_to_integer(ip))
14
14
  end
15
- alias_method :matches?, :datacenter?
15
+ alias_method :classify, :datacenter?
16
16
 
17
17
  def ip_to_integer(ip)
18
18
  Integer === ip ? ip : IPAddr.new(ip).to_i
@@ -55,13 +55,13 @@ class IPCat
55
55
  return nil if last < first # not found, or empty range
56
56
 
57
57
  cur = first + (last - first)/2
58
- case ranges[cur] <=> needle
58
+ case haystack[cur] <=> needle
59
59
  when -1 # needle is larger than cur value
60
60
  bsearch(needle, haystack, cur+1, last)
61
61
  when 1 # needle is smaller than cur value
62
62
  bsearch(needle, haystack, first, cur-1)
63
63
  when 0
64
- ranges[cur]
64
+ haystack[cur]
65
65
  end
66
66
  end
67
67
  end
@@ -1,3 +1,3 @@
1
1
  class IPCat
2
- VERSION = '1.0.1'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.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-01-02 00:00:00.000000000 Z
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 4.4.0
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 4.4.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rake
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -64,7 +64,7 @@ dependencies:
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ~>
67
+ - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: 1.1.3
70
70
  type: :development
@@ -72,7 +72,7 @@ dependencies:
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ~>
75
+ - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: 1.1.3
78
78
  description: ! 'A ruby port of the ipcat library: https://github.com/client9/ipcat/'