ipcat 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ipcat.rb +16 -2
  3. data/lib/ipcat/version.rb +1 -1
  4. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c2b737d8f34461a1e622df44e70d022c8f43ec2
4
- data.tar.gz: 1d05d71f1a1e9090707f76a36f9be9a62890b2c6
3
+ metadata.gz: 53b26b58f5db3eac3747a6d2f3343c927f18b141
4
+ data.tar.gz: 65facf629dacec9d8fff9d3ea22ad65bf5faec7d
5
5
  SHA512:
6
- metadata.gz: 0ad9494ed282c6499b2bca0fe382709af77cb157e75196a98f04ff56f326d0ab519c3aed43797d006c05b75c7bc52999085068d36406998ab867870e85a09841
7
- data.tar.gz: d12e6d35e96ec4ccb6a8afb1ea68f95e4683a9ae7043e2064236885edadb848e78e52642e98bf5621699944ccb7626ad4a4e0b0ea2d96ddc6616910b50c0ed2a
6
+ metadata.gz: 3208a29fdeb662e136de4c05fa2085a1c59bd2f46121db38beb3e5b277d4642f20c9581c9a0b289c0ac036494312a918b4cc658f5662f5384a251717ce9f4f86
7
+ data.tar.gz: 0294d939b02a1305409ec13af6987dfb8d2e8b7fb3682f14c5532c493b0188d7c5e07fa03419a74724adde6dc78c337261de2ba3ce1e8cb46de447b45e07c45f
data/lib/ipcat.rb CHANGED
@@ -10,8 +10,7 @@ require 'ipcat/version'
10
10
  class IPCat
11
11
  class << self
12
12
  def datacenter?(ip)
13
- ip_as_int = ip_to_integer(ip)
14
- ranges.bsearch {|range| range <=> ip_as_int }
13
+ bsearch(ip_to_integer(ip))
15
14
  end
16
15
  alias_method :classify, :datacenter?
17
16
 
@@ -49,6 +48,21 @@ class IPCat
49
48
  rescue
50
49
  load_csv!
51
50
  end
51
+
52
+ # Assume ranges is an array of comparable objects
53
+ def bsearch(needle, haystack=ranges, first=0, last=ranges.size-1)
54
+ return nil if last < first # not found, or empty range
55
+
56
+ cur = first + (last - first)/2
57
+ case haystack[cur] <=> needle
58
+ when -1 # needle is larger than cur value
59
+ bsearch(needle, haystack, cur+1, last)
60
+ when 1 # needle is smaller than cur value
61
+ bsearch(needle, haystack, first, cur-1)
62
+ when 0
63
+ haystack[cur]
64
+ end
65
+ end
52
66
  end
53
67
  end
54
68
 
data/lib/ipcat/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class IPCat
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Suggs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-26 00:00:00.000000000 Z
11
+ date: 2014-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -66,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 2.0.0
69
+ version: 1.9.3
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
@@ -83,4 +83,3 @@ test_files:
83
83
  - spec/ipcat_iprange_spec.rb
84
84
  - spec/ipcat_spec.rb
85
85
  - spec/spec_helper.rb
86
- has_rdoc: