iplogic 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,8 @@
1
+ require 'lib/iplogic'
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'iplogic'
3
- s.version = '0.1.2'
5
+ s.version = IPLogic::VERSION
4
6
 
5
7
  s.authors = ["Jay Adkisson"]
6
8
  s.date = '2010-11-13'
@@ -1,5 +1,5 @@
1
1
  module IPLogic
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
 
4
4
  LIB = File.expand_path(File.dirname(__FILE__))
5
5
  end
@@ -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
@@ -42,14 +42,14 @@ module IPLogic
42
42
  when nil
43
43
  0
44
44
  else
45
- raise ArgumentError, <<-msg.strip
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
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iplogic
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jay Adkisson