Class: PhisherPhinder::ExtendedIpFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/phisher_phinder/extended_ip_factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(geoip_client:) ⇒ ExtendedIpFactory

Returns a new instance of ExtendedIpFactory.



6
7
8
# File 'lib/phisher_phinder/extended_ip_factory.rb', line 6

def initialize(geoip_client:)
  @geoip_client = geoip_client
end

Instance Method Details

#build(ip_string) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/phisher_phinder/extended_ip_factory.rb', line 10

def build(ip_string)
  return nil unless ip_string

  ip = IPAddr.new(ip_string)

  if non_public_ip?(ip) || ip.ipv6?
    SimpleIp.new(ip_address: ip)
  else
    ExtendedIp.new(ip_address: ip, geoip_ip_data: geoip_data(ip_string))
  end
rescue IPAddr::InvalidAddressError
end