ip-ranges 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/ip-ranges/range.rb +11 -0
- data/spec/ip-ranges/range_spec.rb +24 -0
- metadata +3 -3
data/Rakefile
CHANGED
@@ -36,7 +36,7 @@ spec = Gem::Specification.new do |s|
|
|
36
36
|
|
37
37
|
# Change these as appropriate
|
38
38
|
s.name = "ip-ranges"
|
39
|
-
s.version = "0.1.
|
39
|
+
s.version = "0.1.3"
|
40
40
|
s.summary = "Compare and manipulate ranges of IP numbers"
|
41
41
|
s.author = "David Salgado"
|
42
42
|
s.email = "david@digitalronin.com"
|
data/lib/ip-ranges/range.rb
CHANGED
@@ -51,12 +51,23 @@ module IpRanges
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
def to_s
|
55
|
+
if empty?
|
56
|
+
''
|
57
|
+
elsif first == last
|
58
|
+
first.to_s
|
59
|
+
else
|
60
|
+
[first.to_s, last.to_s].join('..')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
54
64
|
# Arguments
|
55
65
|
# * An +Ip+ object
|
56
66
|
# Extend the range if the pushed IP is the next, contiguous ip in the range. Otherwise return false and do nothing.
|
57
67
|
def push(ip)
|
58
68
|
if empty?
|
59
69
|
@first = ip
|
70
|
+
@last = ip
|
60
71
|
true
|
61
72
|
elsif ip.to_s == @last.dup.increment
|
62
73
|
@last = ip
|
@@ -4,6 +4,25 @@ describe IpRanges::Range do
|
|
4
4
|
before do
|
5
5
|
end
|
6
6
|
|
7
|
+
describe "#to_s" do
|
8
|
+
|
9
|
+
it "prints empty string" do
|
10
|
+
range = described_class.new(:range => '')
|
11
|
+
range.to_s.should eq('')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "prints one ip" do
|
15
|
+
range = described_class.new(:range => '1.2.3.4')
|
16
|
+
range.to_s.should eq('1.2.3.4')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "prints dotted range" do
|
20
|
+
range = described_class.new(:range => '1.2.3.4 .. 1.2.3.6')
|
21
|
+
range.to_s.should eq('1.2.3.4..1.2.3.6')
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
7
26
|
context "pushing" do
|
8
27
|
let(:ip1) { IpRanges::Ip.new(:number => '1.1.1.1') }
|
9
28
|
let(:ip2) { IpRanges::Ip.new(:number => '1.1.1.2') }
|
@@ -22,6 +41,11 @@ describe IpRanges::Range do
|
|
22
41
|
empty.push(ip1)
|
23
42
|
empty.first.should eq(ip1)
|
24
43
|
end
|
44
|
+
|
45
|
+
it "sets last ip" do
|
46
|
+
empty.push(ip1)
|
47
|
+
empty.last.should eq(ip1)
|
48
|
+
end
|
25
49
|
end
|
26
50
|
|
27
51
|
context "range with start" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ip-ranges
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Salgado
|