ip 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Rakefile +2 -0
  2. data/lib/ip.rb +2 -2
  3. data/lib/ip/address.rb +28 -0
  4. data/test/test_ip.rb +15 -0
  5. metadata +42 -43
data/Rakefile CHANGED
@@ -59,6 +59,7 @@ spec = Gem::Specification.new do |s|
59
59
  s.has_rdoc = true
60
60
  s.files = Dir['Rakefile'] + Dir['examples/*.rb'] + Dir['lib/*.rb'] + Dir['test/*.rb'] + Dir['lib/ip/*.rb']
61
61
  s.rubyforge_project = 'ip-address'
62
+ s.homepage = "http://github.com/erikh/ip"
62
63
  end
63
64
 
64
65
  Rake::GemPackageTask.new(spec) do |s|
@@ -67,6 +68,7 @@ end
67
68
  Rake::PackageTask.new(spec.name, spec.version) do |p|
68
69
  p.need_tar_gz = true
69
70
  p.need_zip = true
71
+ p.package_files.include("./setup.rb")
70
72
  p.package_files.include("./Rakefile")
71
73
  p.package_files.include("./examples/**/*.rb")
72
74
  p.package_files.include("./lib/**/*.rb")
data/lib/ip.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # IP - Collection of Tools to work with IP addresses
3
3
  #
4
- # Version:: 0.1.0
4
+ # Version:: 0.3.0
5
5
  # Author:: Erik Hollensbe
6
6
  # License:: BSD
7
7
  # Contact:: erik@hollensbe.org
@@ -59,7 +59,7 @@
59
59
 
60
60
  class IP
61
61
 
62
- VERSION = "0.2.2"
62
+ VERSION = "0.3.0"
63
63
 
64
64
  #
65
65
  # A IP::AddressException is thrown when an IP address cannot be
@@ -126,6 +126,20 @@ class IP::Address::IPv4 < IP::Address
126
126
 
127
127
  return IP::Address::Util.raw_pack(packval)
128
128
  end
129
+
130
+ #
131
+ # An IP Address is equal if the ip address match
132
+ #
133
+ def ==(other)
134
+ case other
135
+ when String,Integer,Bignum
136
+ self.ip_address == self.class.new(other).ip_address
137
+ when self.class
138
+ self.ip_address == other.ip_address
139
+ else
140
+ false
141
+ end
142
+ end
129
143
  end
130
144
 
131
145
  class IP::Address::IPv6 < IP::Address
@@ -257,6 +271,20 @@ class IP::Address::IPv6 < IP::Address
257
271
  return IP::Address::Util.raw_pack(self.octets.dup)
258
272
  end
259
273
 
274
+ #
275
+ # An IP Address is equal if the ip address match
276
+ #
277
+ def ==(other)
278
+ case other
279
+ when String,Integer,Bignum
280
+ self.long_address == self.class.new(other).long_address
281
+ when self.class
282
+ self.long_address == other.long_address
283
+ else
284
+ false
285
+ end
286
+ end
287
+
260
288
  protected
261
289
 
262
290
  #
@@ -239,6 +239,14 @@ class IPv6AddressTest < Test::Unit::TestCase
239
239
  assert_equal("F00F:0:0:0:DEAD:BEEF::", ip.short_address, '#short_address returns a compressed version with wildcard @ right')
240
240
  end
241
241
 
242
+ def test_equal
243
+ assert_equal(IP::Address::IPv6.new("F00F::DEAD:BEEF"),IP::Address::IPv6.new("F00F::DEAD:BEEF"))
244
+ assert_equal(IP::Address::IPv6.new("F00F::DEAD:BEEF"), "F00F::DEAD:BEEF")
245
+ assert_equal(IP::Address::IPv6.new("F00F::DEAD:BEEF"), "F00F:0:0:0:0:0:DEAD:BEEF")
246
+ assert_equal(IP::Address::IPv6.new("F00F::DEAD:BEEF"), 319092603441257831911341651915956928239)
247
+ assert !(IP::Address::IPv6.new("F00D::DEAD:BEEF") == IP::Address::IPv6.new("F00F::DEAD:BEEF"))
248
+ assert !(IP::Address::IPv6.new("F00D::DEAD:BEEF") == :someting_else)
249
+ end
242
250
  end
243
251
 
244
252
 
@@ -295,4 +303,11 @@ class UtilTest < Test::Unit::TestCase
295
303
  assert_equal("255.255.255.248", IP::Address::Util.long_netmask_ipv4(29).ip_address, "Long Netmask Test #2")
296
304
  end
297
305
 
306
+ def test_equal
307
+ assert_equal(IP::Address::IPv4.new("255.255.255.255"),IP::Address::IPv4.new("255.255.255.255"))
308
+ assert_equal(IP::Address::IPv4.new("255.255.255.255"), "255.255.255.255")
309
+ assert_equal(IP::Address::IPv4.new("255.255.255.255"), 4294967295) # 255.255.255.255
310
+ assert !(IP::Address::IPv4.new("255.255.255.255") == IP::Address::IPv4.new("255.255.255.254"))
311
+ assert !(IP::Address::IPv4.new("255.255.255.255") == :something_else)
312
+ end
298
313
  end
metadata CHANGED
@@ -1,55 +1,54 @@
1
- --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
1
+ --- !ruby/object:Gem::Specification
4
2
  name: ip
5
- version: !ruby/object:Gem::Version
6
- version: 0.2.2
7
- date: 2008-11-02 00:00:00 -07:00
8
- summary: Ruby classes to work with IP address, ranges, and netmasks
9
- require_paths:
10
- - lib
11
- email: erik@hollensbe.org
12
- homepage:
13
- rubyforge_project: ip-address
14
- description:
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
25
6
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
- authors:
7
+ authors:
30
8
  - Erik Hollensbe
31
- files:
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-11 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: erik@hollensbe.org
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
32
20
  - Rakefile
33
21
  - examples/check-included.rb
34
- - examples/generate-a-records.rb
35
22
  - examples/check-overlap.rb
23
+ - examples/generate-a-records.rb
36
24
  - lib/ip.rb
37
25
  - test/test_ip.rb
38
- - lib/ip/cidr.rb
39
- - lib/ip/util.rb
40
26
  - lib/ip/address.rb
27
+ - lib/ip/cidr.rb
41
28
  - lib/ip/range.rb
42
- test_files: []
43
-
29
+ - lib/ip/util.rb
30
+ homepage: http://github.com/erikh/ip
31
+ licenses: []
32
+ post_install_message:
44
33
  rdoc_options: []
45
-
46
- extra_rdoc_files: []
47
-
48
- executables: []
49
-
50
- extensions: []
51
-
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
52
48
  requirements: []
53
-
54
- dependencies: []
55
-
49
+ rubyforge_project: ip-address
50
+ rubygems_version: 1.8.15
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Ruby classes to work with IP address, ranges, and netmasks
54
+ test_files: []