class Geocoder::IpAddress

def initialize(ip)

def initialize(ip)
  ip = ip.to_string if ip.is_a?(IPAddr)
  if ip.is_a?(Hash)
    super(**ip)
  else
    super(ip)
  end
end

def internal?

def internal?
  loopback? || private?
end

def loopback?

def loopback?
  valid? and !!(self == "0.0.0.0" or self.match(/\A127\./) or self == "::1")
end

def private?

def private?
  valid? && PRIVATE_IPS.any? { |ip| ip.include?(self) }
end

def valid?

def valid?
  ip = self[/(?<=\[)(.*?)(?=\])/] || self
  !!((ip =~ Resolv::IPv4::Regex) || (ip =~ Resolv::IPv6::Regex))
end