iplogic 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/iplogic.gemspec +3 -1
- data/lib/iplogic.rb +1 -1
- data/lib/iplogic/cidr.rb +13 -1
- data/lib/iplogic/ip.rb +3 -3
- metadata +3 -3
data/iplogic.gemspec
CHANGED
data/lib/iplogic.rb
CHANGED
data/lib/iplogic/cidr.rb
CHANGED
@@ -16,7 +16,11 @@ module IPLogic
|
|
16
16
|
when IP
|
17
17
|
netmask_to_bits(bits)
|
18
18
|
else
|
19
|
-
bits.to_i
|
19
|
+
if bits.respond_to? :to_i
|
20
|
+
bits.to_i
|
21
|
+
else
|
22
|
+
format_error(args, bits)
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
new(ip, bits)
|
@@ -24,6 +28,8 @@ module IPLogic
|
|
24
28
|
arg = args.first
|
25
29
|
if arg =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/(\d+)/
|
26
30
|
new($1, $2)
|
31
|
+
else
|
32
|
+
format_error(arg)
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
@@ -34,6 +40,12 @@ module IPLogic
|
|
34
40
|
netmask.to_i.to_s(2) =~ /^(1*)0*$/
|
35
41
|
$1.length
|
36
42
|
end
|
43
|
+
|
44
|
+
FormatError = Class.new(ArgumentError)
|
45
|
+
def format_error(*args)
|
46
|
+
args = args.map { |a| a.inspect }.join(', ')
|
47
|
+
raise FormatError, "CIDR: unable to parse #{args}"
|
48
|
+
end
|
37
49
|
end
|
38
50
|
|
39
51
|
attr_reader :ip, :bits
|
data/lib/iplogic/ip.rb
CHANGED
@@ -42,14 +42,14 @@ module IPLogic
|
|
42
42
|
when nil
|
43
43
|
0
|
44
44
|
else
|
45
|
-
raise
|
46
|
-
Couldn't parse #{arg.inspect} to an IP.
|
47
|
-
msg
|
45
|
+
raise FormatError, "IP: Unable to parse #{arg.inspect}"
|
48
46
|
end
|
49
47
|
|
50
48
|
return new(int)
|
51
49
|
end
|
52
50
|
|
51
|
+
FormatError = Class.new(ArgumentError)
|
52
|
+
|
53
53
|
private
|
54
54
|
def parts_to_int(parts)
|
55
55
|
r = 0
|
metadata
CHANGED