Browse files

Formatted README, rewrote IPAddress::parse and wrote IPv4#parse_class…

…ful test
  • Loading branch information...
1 parent 08b1cef commit f9747c75e0038cdfe1ac8c1605d9f1c63f0369d5 @bluemonk bluemonk committed Sep 7, 2010
Showing with 18 additions and 23 deletions.
  1. +13 −15 README.rdoc
  2. +1 −5 lib/ipaddress.rb
  3. +3 −3 lib/ipaddress/extensions/extensions.rb
  4. +1 −0 test/ipaddress/ipv4_test.rb
@@ -43,10 +43,13 @@ Some quick examples of things you can't do with IPAddr:
* iterate over hosts
* perform subnetting or network aggregation
-Moreover, many methods and procedures are so old that they have been
+Many methods and procedures are so old that they have been
declared deprecated by the IETF, and some others have bugs in their
+Moreover, IPAddress is more robust and is already around 50% faster than IPAddr,
+in addition to provide an organic API with logical separation and OO structure.
We hope that IPAddress will address all these issues and meet all your
needs in network programming.
@@ -80,18 +83,13 @@ documentation with Rake:
The latest documentation can be found online at
{this address}[]
-== Usage
-In this section I will illustrate how to use the IPAddress library
-through some examples of common tasks.
-=== IPv4
+== IPv4
Class IPAddress::IPv4 is used to handle IPv4 type addresses. IPAddress
is similar to other IP Addresses libraries, like Ruby's own
IPAddr. However it works slightly different, as we will see.
-==== Create a new IPv4 address
+=== Create a new IPv4 address
The usual way to express an IP Address is using its dotted decimal
form, such as, and a prefix, such as 24, separated by a
@@ -136,7 +134,7 @@ as we created the following:
host = ""
-==== Handling the IPv4 address
+=== Handling the IPv4 address
Once created, you can obtain the attributes for an IPv4 object:
@@ -171,7 +169,7 @@ use IPv4#to_string
#=> "172.16.10.l/24"
-==== Changing netmask
+=== Changing netmask
You can set a new prefix (netmask) after creating an IPv4
object. For example:
@@ -189,7 +187,7 @@ using the IPv4#netmask= method
#=> ""
-==== Working with networks, broadcasts and addresses
+=== Working with networks, broadcasts and addresses
Some very important topics in dealing with IP addresses are the
concepts of +network+ and +broadcast+, as well as the addresses
@@ -210,7 +208,7 @@ This is very important because, for instance, IP "" is
very different to the previous one, belonging to the very different
network "".
-===== Networks
+==== Networks
With IPAddress it's very easy to calculate the network for an IP
@@ -240,7 +238,7 @@ network or not:
#=> true
-===== Broadcast
+==== Broadcast
The broadcast address is the contrary than the network number: where
the network number has all zeroes in the host portion, the broadcast
@@ -261,7 +259,7 @@ address:
#=> ""
-===== Addresses, ranges and iterators
+==== Addresses, ranges and iterators
So we see that the netmask essentially specifies a range for IP
addresses that are included in a network: all the addresses between
@@ -299,7 +297,7 @@ respectively the first and the last host address in the range
#=> ""
-==== IP special formats
+=== IP special formats
The IPAddress library provides a complete set of methods to access an
IPv4 address in special formats, such as binary, 32 bits unsigned int,
@@ -46,11 +46,7 @@ def IPAddress::parse(str)
when /:.+\./
- begin
- rescue ArgumentError
- end
+ rescue
@@ -1,14 +1,14 @@
-class << Math
+class << Math # :nodoc:
def log2(n); log(n) / log(2); end
if RUBY_VERSION =~ /1\.8/
- class Hash
+ class Hash # :nodoc:
alias :key :index
-class Integer
+class Integer # :nodoc:
def power_of_2?
Math::log2(self).to_i == Math::log2(self)
@@ -468,6 +468,7 @@ def test_classmethod_parse_classful
assert_equal prefix, res.prefix
assert_equal "#{ip}/#{prefix}", res.to_string
+ assert_raise(ArgumentError){ @klass.parse_classful("") }
end # class IPv4Test

0 comments on commit f9747c7

Please sign in to comment.