ipcat 0.1.0 → 1.0.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/lib/ipcat.rb +3 -3
- data/lib/ipcat/iprange.rb +5 -5
- data/lib/ipcat/version.rb +1 -1
- data/spec/ipcat_iprange_spec.rb +1 -1
- metadata +2 -2
data/lib/ipcat.rb
CHANGED
@@ -10,11 +10,11 @@ require 'ipcat/version'
|
|
10
10
|
class IPCat
|
11
11
|
class << self
|
12
12
|
def matches?(ip)
|
13
|
-
bsearch(
|
13
|
+
bsearch(ip_to_integer(ip))
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def ip_to_integer(ip)
|
17
|
+
Integer === ip ? ip : IPAddr.new(ip).to_i
|
18
18
|
end
|
19
19
|
|
20
20
|
def ranges
|
data/lib/ipcat/iprange.rb
CHANGED
@@ -4,16 +4,16 @@ class IPCat
|
|
4
4
|
attr_accessor :first, :last, :name, :url
|
5
5
|
|
6
6
|
def initialize(first, last, name=nil, url=nil)
|
7
|
-
@first = IPCat.
|
8
|
-
@last = IPCat.
|
7
|
+
@first = IPCat.ip_to_integer(first)
|
8
|
+
@last = IPCat.ip_to_integer(last)
|
9
9
|
@name, @url = name, url
|
10
10
|
raise ArgumentError.new("first must be <= last") if @first > @last
|
11
11
|
end
|
12
12
|
|
13
13
|
def <=>(obj)
|
14
14
|
case obj
|
15
|
-
when
|
16
|
-
|
15
|
+
when Integer
|
16
|
+
compare_with_integer(obj)
|
17
17
|
when IPRange
|
18
18
|
# Assume all IPRanges are non-overlapping
|
19
19
|
first <=> obj.first
|
@@ -21,7 +21,7 @@ class IPCat
|
|
21
21
|
end
|
22
22
|
|
23
23
|
protected
|
24
|
-
def
|
24
|
+
def compare_with_integer(i)
|
25
25
|
if first > i
|
26
26
|
1
|
27
27
|
elsif last < i
|
data/lib/ipcat/version.rb
CHANGED
data/spec/ipcat_iprange_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe 'IPCat::IPRange' do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
describe '#<=> for
|
19
|
+
describe '#<=> for integers' do
|
20
20
|
it("should match first") { (range <=> range.first).must_equal 0 }
|
21
21
|
it("should match last") { (range <=> range.last).must_equal 0 }
|
22
22
|
it("should match first-1") { (range <=> range.first - 1).must_equal 1 }
|
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:
|
4
|
+
version: 1.0.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-
|
12
|
+
date: 2013-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|