Class: Where::IpAddress

Inherits:
Base
  • Object
show all
Defined in:
lib/where/ip_address.rb

Constant Summary collapse

GEOPLUGIN_URL =
'http://www.geoplugin.net/json.gp?ip='
FREEGEOIP_URL =
'http://freegeoip.net/json/'

Instance Attribute Summary

Attributes inherited from Base

#city, #country_code, #country_name, #lat, #lng, #neighborhood, #postal_code, #region_code, #region_name, #street, #street_number

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#address, #attributes=, #country, #region, #street_address, #success?

Constructor Details

#initialize(data = '') ⇒ IpAddress

Returns a new instance of IpAddress.



11
12
13
# File 'lib/where/ip_address.rb', line 11

def initialize(data='')
  super(data.to_s.gsub('geoplugin_', ''))
end

Class Method Details

.geocode(address, opts = {}) ⇒ Object



6
7
8
9
# File 'lib/where/ip_address.rb', line 6

def self.geocode(address, opts={})
  api_url = opts[:geocoder] == 'geoplugin' ? GEOPLUGIN_URL : FREEGEOIP_URL
  super(address, api_url)
end

Instance Method Details

#accuracyObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/where/ip_address.rb', line 23

def accuracy
  if street
    'street_address'
  elsif city
    'city'
  elsif region
    'region'
  elsif country
    'country'
  else
    ''
  end
end

#latitude=(val) ⇒ Object



15
16
17
# File 'lib/where/ip_address.rb', line 15

def latitude=(val)
  @lat = val
end

#longitude=(val) ⇒ Object



19
20
21
# File 'lib/where/ip_address.rb', line 19

def longitude=(val)
  @lng = val
end