Method: NetAddr::EUI64.parse
- Defined in:
- lib/eui64.rb
.parse(addr) ⇒ Object
Parse an EUI-64 string into an EUI64 type. This will successfully parse most of the typically used formats such as:
-
aa-bb-cc-dd-ee-ff-00-11
-
aa:bb:cc:dd:ee:ff:00:11
-
aabb.ccdd.eeff.0011
-
aabbccddeeff0011
Although, in truth, its not picky about the exact format as long as it contains exactly 16 hex characters with the optional delimiting characters ‘-’, ‘:’, or ‘.’.
30 31 32 33 34 35 36 37 38 |
# File 'lib/eui64.rb', line 30 def EUI64.parse(addr) addr = addr.strip.gsub(/[\-\:\.]/,"") if (addr.length != 16) raise ValidationError, "Must contain exactly 16 hex characters with optional delimiters." elsif (addr =~ /[^0-9a-fA-F\:]/) raise ValidationError, "#{addr} contains invalid characters." end return EUI64.new(addr.to_i(16)) end |