ip 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ip.rb +23 -1
- data/test/ip.rb +19 -0
- metadata +17 -12
data/lib/ip.rb
CHANGED
@@ -25,6 +25,11 @@
|
|
25
25
|
# perhaps a distant, future release. Any patches that can correct this
|
26
26
|
# issue are most welcome.
|
27
27
|
#
|
28
|
+
# Also: Thanks to Tim Howe, who did a lot of initial bug testing and
|
29
|
+
# 'trial by fire' as this package came out of it's shell. Writing new
|
30
|
+
# methods that made code easier to understand and/or clearer, and
|
31
|
+
# making plenty of suggestions made creating this module much easier.
|
32
|
+
#
|
28
33
|
# ================================================================
|
29
34
|
#
|
30
35
|
# The compilation of software known as ip.rb is distributed under the
|
@@ -262,7 +267,24 @@ class IP
|
|
262
267
|
raise IP::AddressException.new("Fed IP address is not String")
|
263
268
|
end
|
264
269
|
@ip_address = ip_address
|
265
|
-
|
270
|
+
|
271
|
+
#
|
272
|
+
# Unbeknowest by me, to_i will not throw an exception if the string
|
273
|
+
# can't be converted cleanly - it just truncates, similar to atoi() and perl's int().
|
274
|
+
#
|
275
|
+
# Code below does a final sanity check.
|
276
|
+
#
|
277
|
+
|
278
|
+
octets = ip_address.split(/\./)
|
279
|
+
octets_i = octets.collect { |x| x.to_i }
|
280
|
+
|
281
|
+
0.upto(octets.length - 1) do |octet|
|
282
|
+
if octets[octet] != octets_i[octet].to_s
|
283
|
+
raise IP::AddressException.new("Integer conversion failed")
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
@octets = octets_i
|
266
288
|
|
267
289
|
# I made a design decision to allow 0.0.0.0 here.
|
268
290
|
if @octets.length != 4 or @octets.find_all { |x| x > 255 }.length > 0
|
data/test/ip.rb
CHANGED
@@ -198,6 +198,25 @@ class AddressTest < Test::Unit::TestCase
|
|
198
198
|
end
|
199
199
|
|
200
200
|
assert(false, "init test #4") if ip
|
201
|
+
|
202
|
+
ip = nil
|
203
|
+
begin
|
204
|
+
ip = IP::Address.new("255.255.255.255aaaa")
|
205
|
+
rescue IP::AddressException => e
|
206
|
+
assert(true, "init test #5")
|
207
|
+
end
|
208
|
+
|
209
|
+
assert(false, "init test #5") if ip
|
210
|
+
|
211
|
+
ip = nil
|
212
|
+
begin
|
213
|
+
ip = IP::Address.new("255.255.255.")
|
214
|
+
rescue IP::AddressException => e
|
215
|
+
assert(true, "init test #6")
|
216
|
+
end
|
217
|
+
|
218
|
+
assert(false, "init test #6") if ip
|
219
|
+
|
201
220
|
end
|
202
221
|
|
203
222
|
def test_accessor
|
metadata
CHANGED
@@ -3,11 +3,11 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ip
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2006-
|
8
|
-
summary:
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2006-02-08 00:00:00 -08:00
|
8
|
+
summary: Ruby classes to work with IP address, ranges, and netmasks
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
11
|
email: erik@hollensbe.org
|
12
12
|
homepage:
|
13
13
|
rubyforge_project: ip-address
|
@@ -18,23 +18,28 @@ bindir: bin
|
|
18
18
|
has_rdoc: true
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
20
|
requirements:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
25
24
|
version:
|
26
25
|
platform: ruby
|
27
26
|
signing_key:
|
28
27
|
cert_chain:
|
29
28
|
authors:
|
30
|
-
|
29
|
+
- Erik Hollensbe
|
31
30
|
files:
|
32
|
-
|
31
|
+
- lib/ip.rb
|
33
32
|
test_files:
|
34
|
-
|
33
|
+
- test/ip.rb
|
35
34
|
rdoc_options: []
|
35
|
+
|
36
36
|
extra_rdoc_files: []
|
37
|
+
|
37
38
|
executables: []
|
39
|
+
|
38
40
|
extensions: []
|
41
|
+
|
39
42
|
requirements: []
|
40
|
-
|
43
|
+
|
44
|
+
dependencies: []
|
45
|
+
|