Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added prefix parameter to IPv6.parse_data #28

Open
wants to merge 1 commit into from

1 participant

@hannesg

Hi

IPv6.parse_data is the only parse method which doesn't have a prefix parameter. I added it to make to improve consistency.

Cheers
Hannes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 19, 2012
  1. @hannesg
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 4 deletions.
  1. +3 −4 lib/ipaddress/ipv6.rb
  2. +6 −0 test/ipaddress/ipv6_test.rb
View
7 lib/ipaddress/ipv6.rb
@@ -566,14 +566,13 @@ def self.groups(str)
#
# With that data you can create a new IPv6 object:
#
- # ip6 = IPAddress::IPv6::parse_data " \001\r\270\000\000\000\000\000\b\b\000 \fAz"
- # ip6.prefix = 64
+ # ip6 = IPAddress::IPv6::parse_data " \001\r\270\000\000\000\000\000\b\b\000 \fAz", 64
#
# ip6.to_s
# #=> "2001:db8::8:800:200c:417a/64"
#
- def self.parse_data(str)
- self.new(IN6FORMAT % str.unpack("n8"))
+ def self.parse_data(str, prefix=128)
+ return self.new(IN6FORMAT % str.unpack("n8") + '/' + prefix.to_s)
end
#
View
6 test/ipaddress/ipv6_test.rb
@@ -279,6 +279,12 @@ def test_classmethod_parse_data
assert_equal "2001:db8::8:800:200c:417a/128", ip.to_string
end
+ def test_classmethod_parse_data_with_prefix
+ str = " \001\r\270\000\000\000\000\000\b\b\000 \fAz"
+ ip = @klass.parse_data str, 64
+ assert_equal "2001:db8::8:800:200c:417a/64", ip.to_string
+ end
+
def test_classhmethod_parse_u128
@valid_ipv6.each do |ip,num|
assert_equal @klass.new(ip).to_s, @klass.parse_u128(num).to_s
Something went wrong with that request. Please try again.