ipaddress_2 0.11.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9a281ff3a5be006b8e76e2495597ccc727a403f3e43421250088e8a61da18c6
4
- data.tar.gz: 548b551caad2225532081bc4d9203c703c333ee715b84768115c0697b8a7f865
3
+ metadata.gz: b6c14a053c2c3ae5bbf8f4daf54df76a221ece84a46fc3297159c6751ff45746
4
+ data.tar.gz: 13b69795534a2f0f46332c563348de881430a4b432e6cbf9ef7385861ea8b6d8
5
5
  SHA512:
6
- metadata.gz: 48c4eefd3213e47460b477e34872e1c332f1480d620f6d96527f0c5acc7e4051ffefa233ac1b4566193ee9dfc548d040ee38e374968bda778b2f8462336cf792
7
- data.tar.gz: 37c47f2d478e596a7f11daa7dd33f35e888c1ced7e351f4286561dc69853191d2b09b1e46c9d2227055916668381b30fd634e298aa5c9cf9ae35b7376d85b94a
6
+ metadata.gz: ee9429ddb8b2c69b036eabf72159c32ad8d3babc42bbdc747c12029422ddaf3e97c5b6c2daff8cf8ed4aab40db7a4a4995152093f29a6c3d0200fcb06f7c6900
7
+ data.tar.gz: '08ec5f9867b28c8073b9f06c39e15019479762e22892d7822917dde03f835b86b268dd3df6a1570d2e1f28a15c391b39f02740f707187f9fb1204d167b9e2f31'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Enhancements
6
+ * Added 'last' to IPv6
7
+ * Added 'broadcast' to IPv6
8
+
3
9
  ## 0.11.1
4
10
 
5
11
  ### Bugfix
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.1
1
+ 0.12.0
@@ -246,6 +246,63 @@ module IPAddress;
246
246
  to_u128 | @prefix.to_u128 == @prefix.to_u128
247
247
  end
248
248
 
249
+ #
250
+ # Returns a new IPv6 object with the
251
+ # first host IP address in the range.
252
+ #
253
+ # Example: given the 2001:db8:8:800::/64 network, the first
254
+ # host IP address is 2001:db8:8:800::
255
+ #
256
+ # ip = IPAddress("2001:db8:8:800::/64")
257
+ #
258
+ # ip.first.to_s
259
+ # #=> "2001:db8:8:800::"
260
+ #
261
+ # The object IP doesn't need to be a network: the method
262
+ # automatically gets the network number from it
263
+ #
264
+ # ip = IPAddress("2001:db8:9:800::2/64")
265
+ #
266
+ # ip.first.to_s
267
+ # #=> "2001:db8:9:800::"
268
+ #
269
+ def first
270
+ if prefix == 128
271
+ return self
272
+ else
273
+ IPAddress::IPv6::parse_u128(network_u128)
274
+ end
275
+ end
276
+
277
+ #
278
+ # Like its sibling method IPv4#first, this method
279
+ # returns a new IPv4 object with the
280
+ # last host IP address in the range.
281
+ #
282
+ # Example: given the 192.168.100.0/24 network, the last
283
+ # host IP address is 192.168.100.254
284
+ #
285
+ # ip = IPAddress("2001:db8:8:800::/64")
286
+ #
287
+ # ip.last.to_s
288
+ # #=> "2001:db8:8:800:ffff:ffff:ffff:ffff"
289
+ #
290
+ # The object IP doesn't need to be a network: the method
291
+ # automatically gets the network number from it
292
+ #
293
+ # ip = IPAddress("2001:db8:9:800::2/64")
294
+ #
295
+ # ip.last.to_s
296
+ # #=> "2001:db8:9:800:ffff:ffff:ffff:ffff"
297
+ #
298
+ def last
299
+ if prefix == 128
300
+ return self
301
+ else
302
+ IPAddress::IPv6::parse_u128(broadcast_u128)
303
+ end
304
+ end
305
+
249
306
  #
250
307
  # Returns the 16-bits value specified by index
251
308
  #
@@ -771,6 +828,23 @@ module IPAddress;
771
828
  self.class.parse_u128(network_u128, @prefix)
772
829
  end
773
830
 
831
+ #
832
+ # Returns the broadcast address for the given IP.
833
+ # As this is IPv6 it is just the last IP
834
+ #
835
+ # ip = IPAddress("2001:db8:8:800::/64")
836
+ #
837
+ # ip.broadcast.to_s
838
+ # #=> "2001:db8:8:800::"
839
+ #
840
+ def broadcast
841
+ if prefix == 128
842
+ return self
843
+ else
844
+ IPAddress::IPv6::parse_u128(broadcast_u128)
845
+ end
846
+ end
847
+
774
848
  #
775
849
  # Extract 16 bits groups from a string
776
850
  #
@@ -1,3 +1,3 @@
1
1
  module IPAddress
2
- VERSION = "0.11.1"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -128,6 +128,36 @@ class IPv6Test < Minitest::Test
128
128
  assert_equal bits, @ip.bits
129
129
  end
130
130
 
131
+ def test_method_first
132
+ ip = @klass.new("2001:db8:8:800::/64")
133
+ assert_instance_of @klass, ip.first
134
+ assert_equal "2001:db8:8:800::", ip.first.to_s
135
+ ip = @klass.new("2001:db8:8::/48")
136
+ assert_instance_of @klass, ip.first
137
+ assert_equal "2001:db8:8::", ip.first.to_s
138
+ ip = @klass.new("2001:db8::/32")
139
+ assert_instance_of @klass, ip.first
140
+ assert_equal "2001:db8::", ip.first.to_s
141
+ ip = @klass.new("2001:db8::8:800:200c:417a/64")
142
+ assert_instance_of @klass, ip.first
143
+ assert_equal "2001:db8::", ip.first.to_s
144
+ end
145
+
146
+ def test_method_last
147
+ ip = @klass.new("2001:db8:8:800::/64")
148
+ assert_instance_of @klass, ip.last
149
+ assert_equal "2001:db8:8:800:ffff:ffff:ffff:ffff", ip.last.to_s
150
+ ip = @klass.new("2001:db8:8::/48")
151
+ assert_instance_of @klass, ip.last
152
+ assert_equal "2001:db8:8:ffff:ffff:ffff:ffff:ffff", ip.last.to_s
153
+ ip = @klass.new("2001:db8::/32")
154
+ assert_instance_of @klass, ip.last
155
+ assert_equal "2001:db8:ffff:ffff:ffff:ffff:ffff:ffff", ip.last.to_s
156
+ ip = @klass.new("2001:db8::8:800:200c:417a/64")
157
+ assert_instance_of @klass, ip.last
158
+ assert_equal "2001:db8::ffff:ffff:ffff:ffff", ip.last.to_s
159
+ end
160
+
131
161
  def test_method_prefix=()
132
162
  ip = @klass.new "2001:db8::8:800:200c:417a"
133
163
  assert_equal 128, ip.prefix
@@ -399,6 +429,21 @@ class IPv6Test < Minitest::Test
399
429
  end
400
430
  end
401
431
 
432
+ def test_method_broadcast
433
+ ip = @klass.new("2001:db8:8:800::/64")
434
+ assert_instance_of @klass, ip.broadcast
435
+ assert_equal "2001:db8:8:800:ffff:ffff:ffff:ffff", ip.broadcast.to_s
436
+ ip = @klass.new("2001:db8:8::/48")
437
+ assert_instance_of @klass, ip.broadcast
438
+ assert_equal "2001:db8:8:ffff:ffff:ffff:ffff:ffff", ip.broadcast.to_s
439
+ ip = @klass.new("2001:db8::/32")
440
+ assert_instance_of @klass, ip.broadcast
441
+ assert_equal "2001:db8:ffff:ffff:ffff:ffff:ffff:ffff", ip.broadcast.to_s
442
+ ip = @klass.new("2001:db8::8:800:200c:417a/64")
443
+ assert_instance_of @klass, ip.broadcast
444
+ assert_equal "2001:db8::ffff:ffff:ffff:ffff", ip.broadcast.to_s
445
+ end
446
+
402
447
  def test_method_network
403
448
  @networks.each do |addr,net|
404
449
  ip = @klass.new addr
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipaddress_2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bluemonk
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-01-22 00:00:00.000000000 Z
12
+ date: 2019-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler