Class: JDX::Geocoder::IpApi

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/jdx/geocoder/ip_api.rb

Instance Attribute Summary

Attributes included from Base

#data

Instance Method Summary collapse

Methods included from Base

#search

Constructor Details

#initialize(term) ⇒ IpApi

Returns a new instance of IpApi.



8
9
10
# File 'lib/jdx/geocoder/ip_api.rb', line 8

def initialize(term)
  @term = term
end

Instance Method Details

#addressObject



24
25
26
# File 'lib/jdx/geocoder/ip_api.rb', line 24

def address
  "#{city}, #{state_code} #{postal_code}, #{country}".sub(/^[ ,]*/, '')
end

#cityObject



12
13
14
# File 'lib/jdx/geocoder/ip_api.rb', line 12

def city
  data['city']
end

#coordinatesObject

coordinate order is longitude, latitude



49
50
51
# File 'lib/jdx/geocoder/ip_api.rb', line 49

def coordinates
  [longitude, latitude]
end

#countryObject



16
17
18
# File 'lib/jdx/geocoder/ip_api.rb', line 16

def country
  data['country']
end

#country_codeObject



20
21
22
# File 'lib/jdx/geocoder/ip_api.rb', line 20

def country_code
  data['countryCode']
end

#latitudeObject



36
37
38
# File 'lib/jdx/geocoder/ip_api.rb', line 36

def latitude
  data['lat']
end

#longitudeObject



40
41
42
# File 'lib/jdx/geocoder/ip_api.rb', line 40

def longitude
  data['lon']
end

#postal_codeObject



44
45
46
# File 'lib/jdx/geocoder/ip_api.rb', line 44

def postal_code
  data['zip']
end

#stateObject



28
29
30
# File 'lib/jdx/geocoder/ip_api.rb', line 28

def state
  data['regionName']
end

#state_codeObject



32
33
34
# File 'lib/jdx/geocoder/ip_api.rb', line 32

def state_code
  data['region']
end