Class: Workarea::Geolocation
- Inherits:
-
Object
- Object
- Workarea::Geolocation
- Defined in:
- lib/workarea/geolocation.rb
Defined Under Namespace
Classes: Address
Instance Method Summary collapse
- #city ⇒ Object
-
#coordinates ⇒ Array<Number>
can be found.
- #country ⇒ Object
-
#initialize(env = {}, ip = nil) ⇒ Geolocation
constructor
A new instance of Geolocation.
- #latitude ⇒ Object
- #longitude ⇒ Object
- #postal_code ⇒ Object
- #region ⇒ Object
Constructor Details
#initialize(env = {}, ip = nil) ⇒ Geolocation
Returns a new instance of Geolocation.
5 6 7 8 |
# File 'lib/workarea/geolocation.rb', line 5 def initialize(env = {}, ip = nil) @env = env @ip = ip end |
Instance Method Details
#city ⇒ Object
24 25 26 27 28 |
# File 'lib/workarea/geolocation.rb', line 24 def city @env['HTTP_GEOIP2_DATA_CITY_NAME'].presence || @env['HTTP_GEOIP_CITY'].presence || request.try(:city) end |
#coordinates ⇒ Array<Number>
can be found
48 49 50 51 |
# File 'lib/workarea/geolocation.rb', line 48 def coordinates return unless latitude.present? && longitude.present? [latitude, longitude] end |
#country ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/workarea/geolocation.rb', line 10 def country Country[ @env['HTTP_GEOIP2_DATA_COUNTRY_CODE'].presence || @env['HTTP_GEOIP_CITY_COUNTRY_CODE'].presence || request.try(:country_code) ] end |
#latitude ⇒ Object
34 35 36 37 38 |
# File 'lib/workarea/geolocation.rb', line 34 def latitude @env['HTTP_GEOIP2_DATA_LATITUDE'].presence || @env['HTTP_GEOIP_LATITUDE'].presence || request.try(:latitude) end |
#longitude ⇒ Object
40 41 42 43 44 |
# File 'lib/workarea/geolocation.rb', line 40 def longitude @env['HTTP_GEOIP2_DATA_LONGITUDE'].presence || @env['HTTP_GEOIP_LONGITUDE'].presence || request.try(:longitude) end |
#postal_code ⇒ Object
30 31 32 |
# File 'lib/workarea/geolocation.rb', line 30 def postal_code @env['HTTP_GEOIP_POSTAL_CODE'].presence || request.try(:postal_code) end |
#region ⇒ Object
18 19 20 21 22 |
# File 'lib/workarea/geolocation.rb', line 18 def region region_from_geoip2.presence || @env['HTTP_GEOIP_REGION'].presence || request_data['region_code'] end |