Class: Kokki::IPAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/kokki/ip_address.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ IPAddress

Returns a new instance of IPAddress.

Raises:



10
11
12
13
14
# File 'lib/kokki/ip_address.rb', line 10

def initialize(address)
  raise InvalidInputError, "invalid input: #{address}" unless ip_address?(address)

  @address = address
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



8
9
10
# File 'lib/kokki/ip_address.rb', line 8

def address
  @address
end

Instance Method Details

#country_codeObject



16
17
18
19
20
21
22
23
# File 'lib/kokki/ip_address.rb', line 16

def country_code
  @country_code ||=
    [].tap do |out|
      out << Geocoder.search(address)&.first&.country
    rescue Geocoder::Error => _
      out << nil
    end.first
end