Class: Kokki::IPAddress
- Inherits:
-
Object
- Object
- Kokki::IPAddress
- Defined in:
- lib/kokki/ip_address.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
Instance Method Summary collapse
- #country_code ⇒ Object
-
#initialize(address) ⇒ IPAddress
constructor
A new instance of IPAddress.
Constructor Details
#initialize(address) ⇒ IPAddress
Returns a new instance of IPAddress.
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
#address ⇒ Object (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_code ⇒ Object
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 |