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

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

Constructor Details

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

Class Method Details

.response_attributesObject



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

def self.response_attributes
  %w[ip]
end

Instance Method Details

#cityObject



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

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

#coordinatesObject



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

def coordinates
  %w[latitude longitude].map do |l|
    data.fetch('location', {}).fetch(l, 0.0)
  end
end

#countryObject



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

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

#country_codeObject



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

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

#dataObject



61
62
63
# File 'lib/geocoder/results/geoip2.rb', line 61

def data
  @data.to_hash
end

#languageObject



57
58
59
# File 'lib/geocoder/results/geoip2.rb', line 57

def language
  @language ||= default_language
end

#language=(l) ⇒ Object



53
54
55
# File 'lib/geocoder/results/geoip2.rb', line 53

def language=(l)
  @language = l.to_s
end

#postal_codeObject



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

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

#stateObject



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

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

#state_codeObject



25
26
27
# File 'lib/geocoder/results/geoip2.rb', line 25

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