Sha256: a18fef6c1c40ff319717956efe7f7f1700e9108a2d6f2c0abcfa770287bd7ea6
Contents?: true
Size: 926 Bytes
Versions: 20
Compression:
Stored size: 926 Bytes
Contents
module Validators module Ip extend self # Extracted from Ruby 1.8.7 def v4?(addr) matches = addr.match(/\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/) matches && matches.captures.all? {|i| i.to_i < 256} end # Extracted from Ruby 1.8.7 def v6?(addr) # IPv6 (normal) return true if /\A[\da-f]{1,4}(:[\da-f]{1,4})*\Z/i =~ addr return true if /\A[\da-f]{1,4}(:[\da-f]{1,4})*::([\da-f]{1,4}(:[\da-f]{1,4})*)?\Z/i =~ addr return true if /\A::([\da-f]{1,4}(:[\da-f]{1,4})*)?\Z/i =~ addr # IPv6 (IPv4 compat) return true if /\A[\da-f]{1,4}(:[\da-f]{1,4})*:/i =~ addr && v4?($') return true if /\A[\da-f]{1,4}(:[\da-f]{1,4})*::([\da-f]{1,4}(:[\da-f]{1,4})*:)?/i =~ addr && v4?($') return true if /\A::([\da-f]{1,4}(:[\da-f]{1,4})*:)?/i =~ addr && v4?($') false end def valid?(addr) v4?(addr) || v6?(addr) end end end
Version data entries
20 entries across 20 versions & 1 rubygems