Class: Deidentify::DelocalizeIp

Inherits:
Object
  • Object
show all
Defined in:
lib/deidentify/delocalize_ip.rb

Class Method Summary collapse

Class Method Details

.call(old_ip, mask_length: nil) ⇒ Object



5
6
7
8
9
10
# File 'lib/deidentify/delocalize_ip.rb', line 5

def self.call(old_ip, mask_length: nil)
  return old_ip unless old_ip.present?

  addr = IPAddr.new(old_ip)
  addr.mask(mask_length || default_mask(addr)).to_s
end

.default_mask(addr) ⇒ Object



12
13
14
# File 'lib/deidentify/delocalize_ip.rb', line 12

def self.default_mask(addr)
  addr.ipv4? ? 24 : 48
end