Class: Geocoder::Result::Geoip2

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

Direct Known Subclasses

MaxmindGeoip2

Instance Attribute Summary

Attributes inherited from Base

#cache_hit

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #province, #province_code

Constructor Details

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

Class Method Details

.response_attributesObject



47
48
49
# File 'lib/geocoder/results/geoip2.rb', line 47

def self.response_attributes
  %w[ip]
end

Instance Method Details

#address(format = :full) ⇒ Object



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

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

#cityObject



23
24
25
# File 'lib/geocoder/results/geoip2.rb', line 23

def city
  data.fetch('city', {}).fetch('names', {}).fetch('en', '')
end

#coordinatesObject



11
12
13
# File 'lib/geocoder/results/geoip2.rb', line 11

def coordinates
  [latitude, longitude]
end

#countryObject



35
36
37
# File 'lib/geocoder/results/geoip2.rb', line 35

def country
  data.fetch('country', {}).fetch('names',{}).fetch('en','')
end

#country_codeObject



39
40
41
# File 'lib/geocoder/results/geoip2.rb', line 39

def country_code
  data.fetch('country',{}).fetch('iso_code','')
end

#latitudeObject



15
16
17
# File 'lib/geocoder/results/geoip2.rb', line 15

def latitude
  data.fetch('location',{}).fetch('latitude',0.0)
end

#longitudeObject



19
20
21
# File 'lib/geocoder/results/geoip2.rb', line 19

def longitude
  data.fetch('location',{}).fetch('longitude',0.0)
end

#postal_codeObject



43
44
45
# File 'lib/geocoder/results/geoip2.rb', line 43

def postal_code
  data.fetch('postal',{}).fetch('code','')
end

#stateObject



27
28
29
# File 'lib/geocoder/results/geoip2.rb', line 27

def state
  data.fetch('subdivisions',[]).fetch(0,{}).fetch('names',{}).fetch('en','')
end

#state_codeObject



31
32
33
# File 'lib/geocoder/results/geoip2.rb', line 31

def state_code
  data.fetch('subdivisions',[]).fetch(0,{}).fetch('iso_code','')
end