Class | Dnsruby::IPv4 |
In: |
lib/Dnsruby/ipv4.rb
|
Parent: | Object |
Regex | = | /\A(\d+)\.(\d+)\.(\d+)\.(\d+)\z/ | Regular expression IPv4 addresses must match |
address | [R] | A String representation of the IPv4 address. |
# File lib/Dnsruby/ipv4.rb, line 21 21: def self.create(arg) 22: case arg 23: when IPv4 24: return arg 25: when Regex 26: if (0..255) === (a = $1.to_i) && 27: (0..255) === (b = $2.to_i) && 28: (0..255) === (c = $3.to_i) && 29: (0..255) === (d = $4.to_i) 30: return self.new([a, b, c, d].pack("CCCC")) 31: else 32: raise ArgumentError.new("IPv4 address with invalid value: " + arg) 33: end 34: else 35: raise ArgumentError.new("cannot interpret as IPv4 address: #{arg.inspect}") 36: end 37: end