Class: Geocoder::Result::IpinfoIo

Inherits:
Base
  • Object
show all
Defined in:
lib/geocoder/results/ipinfo_io.rb

Instance Attribute Summary

Attributes inherited from Base

#cache_hit, #data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #latitude, #longitude, #province, #province_code

Constructor Details

This class inherits a constructor from Geocoder::Result::Base

Class Method Details

.response_attributesObject


38
39
40
# File 'lib/geocoder/results/ipinfo_io.rb', line 38

def self.response_attributes
  %w(ip region postal)
end

Instance Method Details

#address(format = :full) ⇒ Object


6
7
8
# File 'lib/geocoder/results/ipinfo_io.rb', line 6

def address(format = :full)
  "#{city} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
end

#cityObject


14
15
16
# File 'lib/geocoder/results/ipinfo_io.rb', line 14

def city
  @data['city']
end

#coordinatesObject


10
11
12
# File 'lib/geocoder/results/ipinfo_io.rb', line 10

def coordinates
  @data['loc'].to_s.split(",").map(&:to_f)
end

#countryObject


22
23
24
# File 'lib/geocoder/results/ipinfo_io.rb', line 22

def country
  @data['country']
end

#country_codeObject


30
31
32
# File 'lib/geocoder/results/ipinfo_io.rb', line 30

def country_code
  @data.fetch('country', '')
end

#postal_codeObject


26
27
28
# File 'lib/geocoder/results/ipinfo_io.rb', line 26

def postal_code
  @data['postal']
end

#stateObject


18
19
20
# File 'lib/geocoder/results/ipinfo_io.rb', line 18

def state
  @data['region']
end

#state_codeObject


34
35
36
# File 'lib/geocoder/results/ipinfo_io.rb', line 34

def state_code
  @data.fetch('region_code', '')
end